Macro to 'toggle' Auto Filter

thunderfoot

Board Regular
Joined
May 28, 2004
Messages
229
I want one macro button to toggle 'Auto Filter' on & off. What code do I need to test if 'Field 3' is filtered or not?

The Filter details are:
Code:
Selection.AutoFilter Field:=3, Criteria1:="1"

AND
Code:
Selection.AutoFilter Field:=3
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Check out the FilterMode property.

Code:
Sub ToggleAutofilter()

If ActiveSheet.FilterMode = True Then
    Selection.AutoFilter field:=3
Else
    Selection.AutoFilter field:=3, Criteria1:="1"
End If

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,530
Messages
5,572,695
Members
412,481
Latest member
nhantam
Top