Hello ! I am trying to use the invoke VBA method to run the following VBA code:
Sub FilterMacro()
Dim Lastrow As Long
'Delete
With ActiveWorkbook.Worksheets("Deduction - Filtered")
.AutoFilterMode = False
With Range("W1", Range("W" & Rows.Count).End(xlUp))
.AutoFilter 1, "*No*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
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)"
'Sort
Columns("H:H").Select
ActiveWorkbook.Worksheets("Deduction - Filtered").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Deduction - Filtered").Sort.SortFields.Add Key:=Range( _
"H2:H" & Lastrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Deduction - Filtered").Sort
.SetRange Range("A1:AB" & Lastrow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
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.