Excel VBA find string : Error 2015

前端 未结 2 457
天命终不由人
天命终不由人 2020-12-11 19:39

I have to following code snippet ...

  Public Sub FindText(path As String, file As String)
    Dim Found As Range

    myText = \"test(\"

    MacroBook = Ac         


        
相关标签:
2条回答
  • 2020-12-11 19:48

    You don't need to use 'Set' in your code. You only use this to assign a reference to an object. Try:-

    For Each ws In Workbooks(file).Worksheets
         With ws
    
           Found = .UsedRange.Find(What:=myText, LookIn:=xlFormulas, _
                          LookAt:=xlPart, MatchCase:=False)
    
           If Not Found Is Nothing Then
            ' do stuff
            ' ...
    

    Hopefully this should work.

    0 讨论(0)
  • 2020-12-11 20:07

    As follow up from comments to the Q, Error 2015 occurs because your formula in the sheet returns #VALUE! error. You can handle it using IsError:

    If Not Found Is Nothing Then
        If Not IsError(Found) Then
           ' do sth
        End If
    End If
    
    0 讨论(0)
提交回复
热议问题