AutoFilter Reset

Johnboy

Board Regular
Joined
Oct 25, 2004
Messages
144
I'm trying to reset all autofilters in a workbook. The following macro works if only one sheet in the workbook has autofilters. I get the following error when more then one sheet has autofilters

Run-time error '1004': Method 'ShowAllData' of object '_Worksheet' failed

The folowing code is in "ThisWorkbook"

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.AutoFilterMode Then ws.ShowAllData
    Next ws
End Sub

Thanks
Johnboy
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I'm trying to reset all autofilters in a workbook. The following macro works if only one sheet in the workbook has autofilters. I get the following error when more then one sheet has autofilters

Run-time error '1004': Method 'ShowAllData' of object '_Worksheet' failed

The folowing code is in "ThisWorkbook"

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim ws As Worksheet
    For Each ws In Worksheets
        If ws.AutoFilterMode Then ws.ShowAllData
    Next ws
End Sub

Thanks
Johnboy

Cannot duplicate the error.
 
Upvote 0
I've just encountered this same error with the code in Excel 2003.I'm trying to reset the AutoFilters to show All item and reset the Auto Filters on a save event.Any suggestions welcomed.
 
Upvote 0

Forum statistics

Threads
1,203,542
Messages
6,056,012
Members
444,840
Latest member
RazzelDazel

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