VBA to clear all filters on table on each Worksheet in Workbook

dellzy

Board Regular
Joined
Apr 24, 2013
Messages
146
Dear Excel Experts,

I found many sets of macros to clear all filters in a workbook. I've tried 4 of them but all doesn't seem to work. The filter still exists altho no error when running the macro. Below is one of the codes I tried.
Is there anything I did wrong? Please help because I need to do this for 80 worksheets in each workbook with total 95 workbooks.

Code:
Sub AutoFiltersOff()

  Dim Wks As Worksheet
    
    For Each Wks In Worksheets
      If Wks.AutoFilterMode = True Then
         Wks.UsedRange.AutoFilter
      End If
    Next Wks


End Sub

Thank you in advance.

DZ
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hello Dellzy,

As far as I can tell, you may want to change this line:_

Code:
  Wks.UsedRange.AutoFilter

to

Code:
 wks.AutoFilterMode = False

.......or, to not use the "IF" statement, try:-

Code:
For Each wKs In ThisWorkbook.Worksheets
        wKs.AutoFilterMode = False
    Next wKs

Cheerio,
vcoolio.
 
Upvote 0
Hi,

All of the suggestions above I've tried earlier before posting this questions. All not seem to work.. That's why I feel weird. :(

Hello Dellzy,

As far as I can tell, you may want to change this line:_

Code:
  Wks.UsedRange.AutoFilter

to

Code:
 wks.AutoFilterMode = False

.......or, to not use the "IF" statement, try:-

Code:
For Each wKs In ThisWorkbook.Worksheets
        wKs.AutoFilterMode = False
    Next wKs

Cheerio,
vcoolio.
 
Upvote 0
Hello Dellzy,

I can't see why it wouldn't work. I've just tested both and all is fine. However, I did notice above that I have a mix of upper and lower case with wKs. Sorry!
This should be exactly as you've declared your variable in all parts of the code (Wks). Try adjusting this to see if it sorts it out for you.

Cheerio,
vcoolio.

P.S. Leave out the "UsedRange" part regardless.
 
Last edited:
Upvote 0
All of the suggestions above I've tried earlier before posting this questions. All not seem to work.. That's why I feel weird.
Is your data in a table (not just a range)? Because the codes above won't affect tables.
 
Upvote 0
For data in table, try this:
Code:
Sub unFilters2()
    Dim ws As Worksheet
    Dim tObj As ListObject

    For Each ws In ActiveWorkbook.Worksheets
        For Each tObj In ws.ListObjects
                tObj.AutoFilter.ShowAllData
        Next
    Next ws
End Sub
 
Upvote 1

Forum statistics

Threads
1,214,581
Messages
6,120,368
Members
448,957
Latest member
BatCoder

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
Back
Top