ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find Method doesn't work (https://www.excelbanter.com/excel-programming/282858-find-method-doesnt-work.html)

Slugo

Find Method doesn't work
 
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?

Don Guillett[_4_]

Find Method doesn't work
 
As always, copy/paste your code here. Do NOT send workbook.

--
Don Guillett
SalesAid Software

"Slugo" wrote in message
...
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?




Tom Ogilvy

Find Method doesn't work
 
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


"Slugo" wrote in message
...
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?





All times are GMT +1. The time now is 08:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com