Erase filter with macro button

B

bren

Hi,

I have this code

Sub select()

Selection.AutoFilter Field:=3, Criteria1:="X"
End Sub

The idea is to assign it to a button and when clicking it filters all
x values, and if I click again on this button it deletes the filter. I
don´t know how to do this second step.

THANKS
 
D

Don Guillett

One way
Sub ToggleFilter()
Set sn = Sheets("sheet7")
With sn.Range("a1:c21")
If sn.FilterMode = False Then
.AutoFilter Field:=3, Criteria1:="X"
Else
.AutoFilter
End If
End With
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Hi,

I have this code

Sub select()

Selection.AutoFilter Field:=3, Criteria1:="X"
End Sub

The idea is to assign it to a button and when clicking it filters all
x values, and if I click again on this button it deletes the filter. I
don´t know how to do this second step.

THANKS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top