Option Explicit
Sub retrieve_autofilter_criteria()
'Erik Van Geit
'070425
Dim i As Long
Dim msg As String
Dim check As String
Dim yes As Boolean
With ActiveSheet
If .AutoFilterMode Then
msg = "field" & vbTab & "crit1" & vbTab & "crit2" & vbTab & "operator" & vbLf
For i = 1 To .AutoFilter.Filters.Count
With .AutoFilter.Filters(i)
If .On Then
yes = True
msg = msg & i & vbTab & .Criteria1
check = vbNullString
On Error Resume Next
check = .Criteria2
msg = msg & vbTab & IIf(LenB(check) > 0, check, " ")
On Error GoTo 0
msg = msg & vbTab & filteroperator(.Operator) & vbLf
Else
msg = msg & i & vbTab & "unfiltered"
End If
End With
Next i
msg = IIf(yes, msg, "no filters on")
MsgBox msg, 64, "Autofilter current criteria"
Else
MsgBox "no autofilter on this sheet", 64, "Autofilter"
End If
End With
End Sub
Function filteroperator(i As Long)
Dim operators As Variant
operators = Array("", "xlAnd", "xlOr", "xlTop10Items", "xlBottom10Items", "xlTop10Percent", "xlBottom10Percent")
filteroperator = operators(i)
End Function