Invoke VBA macro suddenly stopped working

Hello ! I am trying to use the invoke VBA method to run the following VBA code:

Sub FilterMacro()
Dim Lastrow As Long

With ActiveWorkbook.Worksheets("Deduction - Filtered")
    .AutoFilterMode = False
    With Range("W1", Range("W" & Rows.Count).End(xlUp))
        .AutoFilter 1, "*No*"
        On Error Resume Next
    End With
    .AutoFilterMode = False
End With

Lastrow = Worksheets("Deduction - Filtered").Range("H" & Rows.Count).End(xlUp).Row

ActiveWorkbook.Worksheets("Deduction - Filtered").Range("L2").Select
ActiveWorkbook.Worksheets("Deduction - Filtered").Range("L2:L" & Lastrow).Formula = "=IF(COUNTIF($H$2:$H2, H2)>1, (L1-Q1), K2)"

ActiveWorkbook.Worksheets("Deduction - Filtered").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Deduction - Filtered").Sort.SortFields.Add Key:=Range( _
    "H2:H" & Lastrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
With ActiveWorkbook.Worksheets("Deduction - Filtered").Sort
    .SetRange Range("A1:AB" & Lastrow)
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
End With
End Sub

This code ran perfectly fine today but then it suddenly stopped working at the line “.AutoFilter 1, “No”” and started giving me the error “vba autofilter method of range class failed”. It works fine in VBA but it suddenly stopped working in UiPath.

This seems like there is some with the range mentioned along the code, is the sheet mentioned is correct

Cheers @Hisuhong

Yes the sheet name is correct. I tried doing it in Excel too and it worked perfectly fine. Furthermore, this same code worked 30 minutes ago and now it keeps giving me this error…

Is any filter applied to that excel records

Sorry, what do you mean by “excel records”?

Like is there filter applied in the excel sheet we are referring to
Cheers @Hisuhong

I’ve tried it with both a filter applied and without a filter applied. But same error @Palaniyappan

@Palaniyappan I figured out the issue. I had to activate that worksheet first. Now it works properly.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.