VBA 'selection.find' error handling

I am running a search in my VBA code using:

Columns("C:C").Select
    Selection.Find(What:=account, after:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate

If the account is not found it returns a run-time error '91. What would be the best way to handle it.  Can I do an 'If then'?  I need to know what the returned value is when it is not found. Or is an error handler better.  I tried using

On error go to _____: but this did not seem to work.

 

Thanks

 

 

Question Info


Last updated October 1, 2018 Views 13,762 Applies to:
Answer

sub findif()

set mf=Columns("C").Find(What:=account, after:=range("c1"), LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False)

if not mf is nothing then msgbox "its at " & mf.row

end sub


Don Guillett MVP Excel SalesAid Software *** Email address is removed for privacy ***
Don Guillett, SalesAid Software
dguillett1@gmail.com

1 person was helped by this reply

·

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.