Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel 2013 VBA Clear All Filters macro

Tags:

macos

excel

vba

It seems older macros are not working. I have proper securtiy set to run VBA macros but when I have tried a few methods for clearing ALL filters on a worksheet, I get a compile error.

Here is what I have tried:

 Sub AutoFilter_Remove() 'This macro removes any filtering in order to display all of the data but it does not remove the filter arrows ActiveSheet.ShowAllData End Sub 

I have buttons on the sheets to clear all filters for ease of use for users since the sheets has a lot of columns that have filters on them.

like image 537
CJSoldier Avatar asked Feb 13 '14 17:02

CJSoldier


People also ask

How do I remove all filters in Excel VBA?

To clear filters on a single column we use the AutoFilter method. We only reference the Field parameter and set the value to the number of the column we want to clear. The Field is the column number of the range the filters are applied to, NOT the column number of the worksheet.

How do you clear all filters in Excel at once?

Re: Button for reset all filters Excel already has a button to turn on/off the Filter, you can find it in the Sort & Filter group under the Data tab. If you have some filters and you want to clear them all, you can go and click this button twice to turn the filters off and then turn it on, this is will clear them all.

How do I Unfilter all sheets in Excel VBA?

If you want to completely remove filters, go to the Data tab and click the Filter button, or use the keyboard shortcut Alt+D+F+F.


2 Answers

Try this:

If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData 
like image 74
CRondao Avatar answered Sep 20 '22 15:09

CRondao


ShowAllData will throw an error if a filter isn't currently applied. This will work:

Sub ResetFilters()     On Error Resume Next     ActiveSheet.ShowAllData End Sub 
like image 45
BobbyA Avatar answered Sep 18 '22 15:09

BobbyA