Find Method doesn't work

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?
 
T

Tom Ogilvy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top