Question : Cells.Find Problems

Hello all, I use the following VBA code:

    Cells.Find(What:=VARIABLE_NAME, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False).Activate

it obviously works all hunky dory if a match is found but it throws an error if the specific variable does not exist.  Is it possible to ignore the error and just have a flag that states whether or not the search was successful?

Many thanks in advance, Alan.

Answer : Cells.Find Problems

Your find code may be trying to do too much:

dim r as range
on error resume next
set r=Cells.Find(What:=VARIABLE_NAME, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False)
if err()<>0 then

   [do what you would do if the search failed]
else
  r.activate
endif
on error goto 0


This assumes that there is no ON ERROR thing in place in the procedure.  Otherwise, this code would interfere with it.
Random Solutions  
 
programming4us programming4us