Check Autofilter on Workbook open

Peter.Stevens2

Board Regular
Joined
Sep 16, 2008
Messages
56
Hi, I've got a problem and I think its one of those simple solutions that is impssible until someone points out the obvious!

Basically I want to check to see if a certain worksheet has an autofilter applied to it when the workbook is opened, and if there is I want to remove the autofilter (ShowAllData not remove autofilter buttons) before it does anything else. The problem I'm having is accounting for when there isn't an autofilter applied and the ShowAllData errors out.

Any Help would be greatly appreciated!

Thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

This code goes in the ThisWorkbook Class Module:
Code:
Private Sub Workbook_Open()
    
    With Sheet1
        If .AutoFilterMode Then .ShowAllData
    End With
    
End Sub

Change the sheet's codename to suit.

Colin
 
Upvote 0
Hi Colin

Thanks for your quick reply, I thought it would be something like that! I'm still getting an error when I try to open the workbook when AutoFilterMode is on but there are no filters applied to any of the fields. I think the next issue is that there could be a filter on any one of about 40 fields when the workbook is closed.

Kind Regards

Pete
 
Upvote 0
Hi Pete,

My apologies... does this work?

Code:
Private Sub Workbook_Open()
    
    With Sheet1
        If .FilterMode Then .ShowAllData
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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