Clear filters macro not working

imatomic

New Member
Joined
Jan 28, 2008
Messages
31
I recorded these filter events and they are stored in one module. It malfunctions on "ActiveSheet.ShowAllData". Funny thing is as I tested them they worked until I got to the fifth macro. Now none will run?? I'm perplexed.

End goal was to tie these to data valadation selections.

Code:
Sub Clear_Filter()
    ActiveSheet.ShowAllData
End Sub

Sub One()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=3, Criteria1:="1"
End Sub

Sub Two()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=3, Criteria1:="2"
End Sub

Sub Three()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=3, Criteria1:="3"
End Sub

Sub A()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=4, Criteria1:="a"
End Sub

Sub B()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=4, Criteria1:="b"
End Sub

Sub C()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=4, Criteria1:="c"
End Sub

Sub D()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=4, Criteria1:="d"
End Sub

Sub E()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=4, Criteria1:="e"
End Sub

Sub F()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=4, Criteria1:="f"
End Sub

Sub G()
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$8:$Q$200").AutoFilter Field:=4, Criteria1:="g"
End Sub

Looking for any suggestions. Thanks
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,461
Try replacing...

Code:
ActiveSheet.ShowAllData

with

Code:
[COLOR=darkblue]If[/COLOR] ActiveSheet.FilterMode [COLOR=darkblue]Then[/COLOR] ActiveSheet.ShowAllData

or

[COLOR=darkblue]With[/COLOR] ActiveSheet
    [COLOR=darkblue]If[/COLOR] .FilterMode [COLOR=darkblue]Then[/COLOR] .ShowAllData
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]

Hope this helps!
 

Watch MrExcel Video

Forum statistics

Threads
1,127,542
Messages
5,625,416
Members
416,101
Latest member
CCoetzee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top