Runtime error 91

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have defined MySortRange to be $A$11:$K$400, I wrote the following macro to
find a cell after sorting MySortRange:

Dim CellValue
CellValue = Range("A3").Value
Range("MySortRange").Find(CellValue).Activate

I get "Runtime error 91, Object variable or With block not set"
Any suggestions? The wierd part is that this worked last night and now it
doesn't.

Thanks in advance.
 
If the find method does not 'find' anything it will return nothing.
Trying to activate a range of nothing will cause an error.

It would probably be better to return that find result to anothe
working variable

ie
rngFound = Range("MySortRange").Find(CellValue).

then test the result for 'nothingness'

eg

if NOT rngFound is nothing then
rngfound.activate
end if


HI
 
Thanks, that is helpful, but it is didn't solve my problem regarding why it
can't find the text string that I am looking for. This is what I finally got
to work:

A3 contains the text "November 2004"

In my macro I added the following:

Range("MySortRange").Find(Range("A3").Value, LookIn:=xlValues).Activate

This line of code finds and selects the cell in my MySortRange with
"November 2004". I only have one cell with this value in it. I think the
"Lookin:=xlValues" was the key.
 
Back
Top