Autofilter Subscript out of range

2k views Asked by At

I've been trying to filter for 5 values in column O. These values may or may not exist. What I've been trying are the two following examples:

ActiveSheet.ListObjects("Sheet1").Range.AutoFilter Field:=15, Criteria1:= _
            Array("CONS", "MISC", "PFG", "PRT", "TOTE"), _
            Operator:=xlFilterValues
            ActiveSheet.Range("$O$8:$O").SpecialCells(xlCellTypeVisible).EntireRow.DELETE
Range("O8").AutoFilter Field:=15

and

ActiveSheet.Range("$O$8:$O").AutoFilter Field:=15, Criteria1:="=CONS", _
            Operator:=xlOr, Criteria2:="=MISC", _
            Operator:=xlOr, Criteria3:="=PFG", _
            Operator:=xlOr, Criteria4:="=PRT", _
            Operator:=xlOr, Criteria5:="=TOTE"
        ActiveSheet.Range("$O$8:$O").SpecialCells(xlCellTypeVisible).EntireRow.DELETE
Range("O8").AutoFilter Field:=15

The first block of code gives me the error: Subscript out of range. The second gives the error: Application-defined or object-defined error.

Does anyone see what's wrong with these?

Thank you.

1

There are 1 answers

2
Abe Gold On

Try

    ActiveSheet.Range("$O$8:$O$10000").AutoFilter Field:=1, Criteria1:=Array("MISC" _
        , "MISC", "PFG", "PRT", "TOTE", "="), Operator:=xlFilterValues
    ActiveSheet.Range("$O$8:$O10000").SpecialCells(xlCellTypeVisible).EntireRow.Delete
    Range("O8").AutoFilter Field:=1