如何检测VBA excel是否find了一些东西?

我使用这个在macros中find我的工作表中的东西:

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

我怎么知道它是否发现了什么?

 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 

Find返回一个Range对象,如果没有findWhat ,这个对象将不值。 从帮助:

 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 

Selection.Find就像使用Ctrl + F来查找一个值。 然后你可以检查Activecell.Value,看看你是否得到了预期的结果。