Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help on using find method 1

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
Basically all I want to do is use the Find method to search for a string of text. However, if excel doesnt find the string it gives you a visual basic error sayin runtime "error 91 object variable or with block variable not set", so im trying to avoid this error. I just want excel to not do anything if it can't find the string. I tried with the following code but it didnt work, thanks

Cells.Find(what:="text", after:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

If ActiveCell.Value <> &quot;text&quot; Then End
 
The find method doesn't change the activecell. You need to assign your .find call to a range variable, e.g.

dim cell as range
...
set cell=cells.find ....

if cell is Nothing then
msgbox &quot;Not found!&quot;
else
do your stuff, e.g.
cell.font.color=vbRed
end if
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top