I am trying to filter a table based of 2 criteria.
Every time my macro runs, it displays the
Run-time Error '5'. Invalid procedure call or argument.
message once it gets to filtering the sheet.
I've switched laptops and copied the macro word by word and saved it in my personal macro book. With my previous laptop, this macro ran without error (my previous laptop was a Lenovo and this one is a Dell).
vba code
Range("A2:X2").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Range("A:X").AutoFilter Field:=16, Criteria1:="<>*East*", Criteria2:="<>*VO*", Operator:= xlFilterValues
Selection.ClearContents
ActiveSheet.Range("A:X").AutoFilter Field:=16, Criteria1:="PR VO"
ActiveSheet.Range("A:X").AutoFilter Field:=11, Criteria1:="<>*EC *", Operator:= xlFilterValues
Selection.ClearContents
ActiveSheet.Range("A:X").AutoFilter Field:=11
ActiveSheet.Range("A:X").AutoFilter Field:=16
ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Add Key:=Range ("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
I expect this code to filter the values that do not match the criteria and clear that data. This is basically to filter out candidates for our Eastern Cape Region. The result however, is Run-time Error '5'. Invalid procedure call or argument.