Runtime Error 91 in Excel/VBA

Solved
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 answers

  • Votes
  • Date
  • Descending date
  1. Contributor
    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
    1. Thank you for your code, it's still valid, even 11 years later ;-)