I am kind of new to objects in Excel even though I have been programing in it for over 15 years. I thought this would work but I get the error:
Object variable or with block variable not set
I have the line that called this as:
COCell = FindCustomOption(COs, SelTask)
In the calling function I have, "Dim COCell As Range"
I am using Excel 2010.
Thanks,
Object variable or with block variable not set
I have the line that called this as:
COCell = FindCustomOption(COs, SelTask)
In the calling function I have, "Dim COCell As Range"
Code:
Public Function FindCustomOption(Ws As Worksheet, Task As String) As Range
'Created by David Follmann September 21, 2013
'FINDS THE TASK ON THE SPECIFIED WORKSHEET AND RETURNS THE CELL
Const FstDataRow As Integer = 4, ColOff As Integer = 4 'First Data Row and Column Offsets
Dim CRow As Integer, CCol As Integer 'Current Row and Column
Dim TaskFound
Const CO As String = "Custom Options" 'Custom Options worksheet
Dim COs As Worksheet 'Create object for Custom Options worksheet
CRow = FstDataRow
CCol = 2
Set COs = Sheets(CO) 'Point the object to the Custom Options worksheet
Do While COs.Cells(CRow, CCol + 1) <> "" 'NO: Is there an option description to the right of this box?
Do While COs.Cells(CRow, CCol + 1) <> "" ' NO: Is there an option description to the right of this box?
If COs.Cells(CRow, CCol + 1) = Task Then ' YES: Again, is there an option description to the right of this box in this column?
FindCustomOption = COs.Cells(CRow, CCol + 1)
TaskFound = True
End If
CRow = CRow + 1
Loop ' CHECK AGAIN
CRow = FstDataRow ' Move the Current Row back to the First Data Row
CCol = CCol + ColOff ' Advance the Column by the Column Offset
Loop ' CHECK AGAIN
If Not TaskFound Then
FindCustomOption = Cells(1, 1)
End If
End Function
I am using Excel 2010.
Thanks,