2014-10-30 49 views
0

我在Excel宏中使用查找方法在單元格中搜索VLOOKUP,我的目標是我需要知道哪個公式不包含VLOOKUP,我的方法運行良好,直到在細胞有 沒有VLOOKUP和宏觀不停地調試與運行時錯誤「91」查找方法在Excel中引發錯誤91宏

我的問題是我應該如何正確地寫宏,所以我不會得到調試,直到activecell 包含*,下面是我的宏:

Sub findvlookup() 

    Do While Not ActiveCell.Value = "*" 

     If Selection.Find(What:="VLOOKUP", After:=ActiveCell, LookIn:=xlFormulas, _ 
      LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ 
      MatchCase:=False, SearchFormat:=False).Activate Then 

      ActiveCell.Offset(1, 0).Select 

     End If 

    Loop 

End Sub 

Tha爲幫助

+0

? (黃色調試線) – 2014-10-30 10:59:31

回答

0

NKS你並不需要一個循環來找到你「什麼的第一次出現:=」字符串

Dim fndVL as Range 

fndVL = Selection.Find(What:="VLOOKUP", After:=ActiveCell, LookIn:=xlFormulas, _ 
    LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ 
    MatchCase:=False, SearchFormat:=False) 

If Not fndVL is Nothing Then 
    MsgBox "Found it" 
Else 
    NsgBox "Not found" 
End If 

如果你想找到後續實例,然後看看FindNext和可能在循環內使用它。

0
Sub findvlookup() 

Dim rngFind As Range 

Do While Not ActiveCell.Value = "*" 

    Set rngFind = Selection.Find(What:="VLOOKUP", After:=ActiveCell, LookIn:=xlFormulas, _ 
     LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ 
     MatchCase:=False, SearchFormat:=False) 

     If Not rngFind Is Nothing Then 

      ActiveCell.Offset(1, 0).Select 

     Else 
      Exit Sub 
     End If 



Loop 

End Sub 
0

您正在使用的查找方法,技術細節是Here

你可以找到(例如)認爲:

常見Err.Numbers(9,91):指定文本是不是在目標工作簿。

如果你有一個細胞有一個錯誤值,就會有另一種類型的錯誤:像那個錯誤發生什麼線#Value