PDA

Click to See Complete Forum and Search --> : Selection.Find, true or false?


jeffcravener
Jan 26th, 2005, 02:34 PM
I have the following 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.

RobDog888
Jan 26th, 2005, 04:09 PM
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.
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 IfHTH

jeffcravener
Jan 27th, 2005, 07:35 AM
Thank you!!

RobDog888
Jan 27th, 2005, 02:17 PM
No problem. I remembered I wrote the code recently. So easy for me. :D

jeffcravener
Jan 27th, 2005, 02:33 PM
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.

RobDog888
Jan 27th, 2005, 02:39 PM
Weird, could you post the code?

jeffcravener
Jan 27th, 2005, 02:41 PM
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!

RobDog888
Jan 27th, 2005, 03:18 PM
Dont worry about it. We all have those days. ;)