Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect whether VBA excel found something?

Tags:

excel

vba

i am using this to in a macro to find stuff in my sheet:

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

how can i tell whether or not it found something?

like image 645
Alex Gordon Avatar asked Oct 19 '09 17:10

Alex Gordon


1 Answers

Dim rng As Range

Set rng = Selection.Find(What:=email, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=False)

If Not rng Is Nothing Then 'when rng <> nothing means found something'
    rng.Activate
End IF
like image 54
manji Avatar answered Sep 23 '22 06:09

manji