Find Method doesn't work

  • Thread starter Thread starter Slugo
  • Start date Start date
S

Slugo

I have a function that uses the find method to search for
a string within a spreadsheet. It works fine when called,
except when I call it from a For loop I get a RunTime erro
91: Object variable or with block variable not set.

Does anybody know why I keep getting this?
 
I suspect you have a construct like

cells.Find("target").Select

if the target is not found, cells.find resolves to nothing so you have

nothing.Select
which raises that error. You should do

set rng = cells.find("target")
if not rng is nothing then
rng.select
Else
msgbox "Target not found"
End if

Regards,
Tom Ogilvy
 
Back
Top