Runtime Error 91 in Excel/VBA

Solved
maxbvs Posted messages 2 Registration date   Status Membre -  
 Thierry17 -
Hello,

Following a macro run, I am getting the "famous" runtime error 91
Here is the highlighted code that may be causing the error:

Cells.Find(What:=pprod, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

"pprod" is declared correctly before,

Can someone help me ???????

Thank you in advance

MaXBvs
Configuration: Windows XP Firefox 2.0.0.11

2 réponses

gbinforme Posted messages 14930 Registration date   Status Contributeur Last intervention   4 742
 
hello

You attempted to use an object variable that has the value Nothing.

That's what the documentation says, and actually this happens often when using "find".

I think it's because of using activate, as you cannot select what you haven't found.

Personally, I set a range object and test for nothing before using it.

set sel = Cells.Find(What:=pprod, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
if sel is nothing then
code not found
else
sel.select
endif

--

always zen
11
Thierry17
 
Thank you for your code, it's still valid, even 11 years later ;-)
1