Remove filter in worksheets before running code

G

gootroots

How do I include all sheets in a workbook when running the following:

If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If

Thanks
 
M

Mike H

Hi,

Sub Show_All()
For x = 1 To Worksheets.Count
If Sheets(x).FilterMode Then
Sheets(x).ShowAllData
End If
Next
End Sub

Mike
 
G

gootroots

Hi Mike

It's stalling on X when put into the body of other code. Not quite sure why.
 
M

Mike H

Hi,

I'm not sure what you mean. There's no need to alter the code at all simply
run it as I posted it and it will clear the filters an all sheets

Mike
 
J

john

Hi Mike,
You omitted Declaring X in your code & me thinks OP has Option Explicit
declared at top of module?
 
G

gootroots

You are right John,
I have Option Explicit declared at top of module

What do I need to change now to make it work.
 
M

Mike H

Hi,

This will cure it

Sub Show_All()
Dim X as Long
For x = 1 To Worksheets.Count
If Sheets(x).FilterMode Then
Sheets(x).ShowAllData
End If
Next
End Sub

Mike
 
Top