2014-10-30 37 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