sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
Hi,
I have this issue of people saving a shared workbook with filtered columns in the tables or sometimes turning the autofilter completely off. This workbook has many tables and some worksheets have as many as 6 tables on them. I need to be able to force the autofilter on for any tables in the workbook where a user turned them off by accident and likewise, if the user leaves a table with a filtered column and saves it that way, I need the column filter turned off and just the table filter left on. The code I found below does take care of turning off any table columns that are filtered, but I cannot figure out how to get this code to do the rest.
Any help would be much appreciated.
Thanks, SS
I have this issue of people saving a shared workbook with filtered columns in the tables or sometimes turning the autofilter completely off. This workbook has many tables and some worksheets have as many as 6 tables on them. I need to be able to force the autofilter on for any tables in the workbook where a user turned them off by accident and likewise, if the user leaves a table with a filtered column and saves it that way, I need the column filter turned off and just the table filter left on. The code I found below does take care of turning off any table columns that are filtered, but I cannot figure out how to get this code to do the rest.
Any help would be much appreciated.
Thanks, SS
VBA Code:
Sub ResetFilters()
On Error Resume Next
For Each wrksheet In ActiveWorkbook.Worksheets
wrksheet.ShowAllData 'This works for filtered data not in a table
For Each lstobj In wrksheet.ListObjects
If lstobj.ShowAutoFilter Then
lstobj.Range.AutoFilter 'Clear filters from a table
lstobj.Range.AutoFilter 'Add the filters back to the table
End If
Next 'Check next worksheet in the workbook
Next
End Sub