How to use a loop to clear all filters in all tables in a workbook?

M McAllister

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

I have workbook with 6 data tables fed by data connections. When I close the workbook, I want to clear all the filters in each of the tables before saving and closing the workbook.

I have a lazy macro that loops through the each table and sheet, but doesn't clear the table filters.

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

Any help is appreciated.

Thanks,
Mathew
 
I solved the table update by changing the 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

The tables update but it's throwing an error "Run-time error '91': Object variable or With block variable not set". The highligted line in the debug is:

Code:
If lo.AutoFilter.FilterMode Then

I've looked at examples but I don't know how to solve this.
Any help is appreciated. Thank you in advance.

Mathew
 
Last edited:
Upvote 0

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