Name

autofilter.Filters(index)

Synopsis

The Filters collection returns a Filter object with read-only properties that list the state and criteria for each filtered column on the worksheet. You can’t change or apply filters through the Filters collection; you can only read the settings and then only if the filter is on as shown here:

Sub ShowFilters(  )
    Dim ws As Worksheet, flt As Filter, i As Integer
    Set ws = ActiveSheet
    ' If there are filters
    If ws.AutoFilterMode Then
        ' Get each Filter object
        For i = 1 To ws.AutoFilter.Filters.Count
            Set flt = ws.AutoFilter.Filters(i)
            '  And if the filter is on, show its criterion.
            If flt.On Then
                Debug.Print "Column " & i & ": " & flt.Criteria1
            End If
        Next
    End If
End Sub

Warning

Use the Range object’s AutoFilter method to set Filter properties and apply filters.

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.