How do I clear filters in Worksheets and Tables?

M McAllister

New Member
Joined
Apr 16, 2013
Messages
15
Using Excel 2010 on Windows 7,

I have a workbook with many sheets, some of which contain more than 1 data data table that is fed by data connections.

I have the following code. When the code runs, if the cursor is within a table, the table's filters are cleared. But if the active cell is not in the table, then the tables filters are not cleared.

Code:
Dim ws As Worksheet
    
    For Each ws In ActiveWorkbook.Worksheets
        With ActiveSheet
           If .FilterMode Or .AutoFilterMode Then
                .ShowAllData
            End If
        End With
    Next

I want to loop through each table and clear any filter, if it exists.

How do I make this happen?

Any help is greatly appreciated.
Thank you,
Mathew
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Okay I found and modified my code to this:
Code:
Dim ws As Worksheet
    Dim lo As ListObject
    
    For Each ws In ActiveWorkbook.Worksheets
        For Each lo In ws.ListObjects
            If lo.AutoFilter.FilterMode Then
                lo.AutoFilter.ShowAllData
            End If
        Next
    Next
That clears the filters but it also throws an error:
Run-Time error '91':
Object variable or with block variable not set

What's up with that?

Thanks,
Mathew
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,020
Members
449,203
Latest member
tungnmqn90

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