2009-10-19 92 views

回答

12
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 
2

Find如果未找到What,則返回值爲Nothing的Range對象。從幫助:

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 
1

Selection.Find就像是用Ctrl + F查找的值。然後,您可以檢查Activecell.Value以查看是否獲得了期望的結果。

相關問題