I'm very much a noob at VBA for Excel. I'm trying to write a function that will return the row number of a cell where certain data is located. In the code below, the data is all located in column B, and I'm trying to find the row number of the cell containing the string "d1".
Function d1row()
d1row = Range("B:B").Find(What:="d1", _
After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Row
End Function
All I get is the #VALUE! error in the worksheet cell where I enter the function. I've tried many variations on the Find parameters, but always the same result.
What am I doing wrong?
Function d1row()
d1row = Range("B:B").Find(What:="d1", _
After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Row
End Function
All I get is the #VALUE! error in the worksheet cell where I enter the function. I've tried many variations on the Find parameters, but always the same result.
What am I doing wrong?