Selection.Find, true or false?
I have the following code:
Code:
Range("B7:AA7").Select
Selection.Find(What:=strWT, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
If the string in strWT is not found, it errors out.
How can I test it to find out if it found the strWT or ont, so that i can pop up a message that says Can not find strWT?
Looked for an answer on the posts, but couldn't find anything specific to the above.
Re: Selection.Find, true or false?
A Find will return a range. so if you set a range to a Find and then test the
range you can determine if it was found or not.
VB Code:
Dim r As Range
Set r = Sheets(1).Cells.Find(what:="#11#")
If TypeName(r) <> "Nothing" Then
MsgBox r.Cells.Row & " - " & r.Cells.Column
r.Replace what:="#11#", Replacement:="#22#"
Else
MsgBox "Not found"
End If
HTH
Re: Selection.Find, true or false?
No problem. I remembered I wrote the code recently. So easy for me. :D
Re: Selection.Find, true or false?
Actually.....a related question.
The code is within a loop...so I am trying to clear R, so it does equal nothing befoe the next iteration.
But, it is holding the last value.
I tried:
Set r = Nothing
But its not working.
Re: Selection.Find, true or false?
Weird, could you post the code?
Re: Selection.Find, true or false?
Ignore me!!!
I figured out wah t iwas doing.
It was finding the string in another location on the page.
so i changed Cells.Find to Selection.Find.
sorry for the bother!
Re: Selection.Find, true or false?
Dont worry about it. We all have those days. ;)