View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dave Dave is offline
external usenet poster
 
Posts: 1,388
Default Trouble with types...

Im trying to write a macro to pull data out of another workbook, and have
written a function GetValue that does this, but since im relatively new to
vba I keep getting type mismatches with whatever values i put into it. Thanks
in advance.

Sub Update()
Sheets(ActiveSheet).Visible = True
pathToFolder= Sheets("Combined Results").Range("C3")
file = ActiveSheet.Range(ActiveCell)
sheet = "CQR"

Application.ScreenUpdating = False
Sheets("Call Quality Results").Visible = True
reference = Cells(C, 21).Address
ActiveCell.Offset(0, 1) = GetValue(pathToFolder, file, sheet, reference)
Application.ScreenUpdating = True

End Sub

Private Function GetValue(path, file, sheet, ref)
Dim arg As String
If Right(path, 1) < "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address(, , xlR1C1)
GetValue = ExecuteExcel4Macro(arg)
End Function