(Solved) – Find a match in workbook using Excel VBA: run-time error 1004


I try to create a macro, which searches the word “Routing” in all my sheets of my active workbook.

Then when it detects this word as first occurrence in one of my sheet of my workbook, I want my macro to select the related cell on the corresponding sheet.

Unfortunately, it does not work because my macro returns the following error message:

run-time error 1004: activate method of range class failed…

It seems that this line of code in my macro generates the issue: Loc.Activate

Please find the code of my macro below.

Thanks in advance for the one who can help me.

Sub FindAndExecuteRouting()
Dim Sh As Worksheet
Dim Loc As Range
For Each Sh In ActiveWorkbook.Worksheets
    With Sh.UsedRange
        Set Loc = .Cells.Find(What:="Routing")
If Not Loc Is Nothing Then
End If
    End With
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *