How to determine if VBA excel has found something?

I use this for macro to find material 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 find out if I found anything?

+4
source share
3 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 
+13
source

Find returns a Range object that will have the value ave Nothing if What not found. Via:

 With Worksheets(1).Range("a1:a500") Set c = .Find(2, lookin:=xlValues) If Not c Is Nothing Then firstAddress = c.Address Do c.Value = 5 Set c = .FindNext(c) Loop While Not c Is Nothing And c.Address <> firstAddress End If End With 
+2
source

Selection.Find is like Ctrl + F to find a value. Then you can check Activecell.Value to find out if you have the desired result.

+1
source

All Articles