Hi
I have a problem setting a range object to be returned from one of my functions. I use a set keyword to set the return value (which is accepted), but I get the error:
"Object variable or With block variable not set (Error 91)"
when I run the code.
I call the function with:
Code:
rTarget = FindVal(wstTarget.Name, sDate, sTOB)
and the function itself is:
Code:
Function FindVal(sSheet As String, sDate As String, sTOB As String) As Range
' Return cell range for target value
Dim iRow As Integer
Dim iCol As Integer
iRow = 2
iCol = 2
Dim wstSheet As Worksheet
Set wstSheet = ThisWorkbook.Worksheets(sSheet)
Do Until wstSheet.Cells(iRow, 1).Value = sTOB
iRow = iRow + 1
Loop
Do Until wstSheet.Cells(1, iCol).Value = sDate
iCol = iCol + 1
If wstSheet.Cells(1, iCol).Value = "" Then
Exit Do
End If
Loop
Set FindVal = wstSheet.Cells(iRow, iCol)
End Function
Does anyone have any idea what is wrong? When I debug the code, I get the error on the End Function line, but it steps through all the rest of the code in the fuction OK.
Thanks