asma410
New Member
- Joined
- Feb 1, 2005
- Messages
- 35
Hello,
How do I capture the return value of a FIND function when the searched item cannot be found?
I am trying to locate 'mystring' in various worksheets but the variable 'strCheck' is always 'True' & vbNullString is always "", so how do I correctly capture the value returned from the search? The code below works fine but the results are not accurate. Please point out what I am doing wrong.
Thanks in advance.
With Range("A1:A2000")
On Error Resume Next
strCheck = Cells.Find(What:=mystring, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
On Error GoTo 0
End With
'if string is found....
If strCheck <> vbNullString Then
'do stuff
End if
How do I capture the return value of a FIND function when the searched item cannot be found?
I am trying to locate 'mystring' in various worksheets but the variable 'strCheck' is always 'True' & vbNullString is always "", so how do I correctly capture the value returned from the search? The code below works fine but the results are not accurate. Please point out what I am doing wrong.
Thanks in advance.
With Range("A1:A2000")
On Error Resume Next
strCheck = Cells.Find(What:=mystring, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
On Error GoTo 0
End With
'if string is found....
If strCheck <> vbNullString Then
'do stuff
End if
Last edited: