Apr 22 2022 02:49 PM
I have an Excel file that I need to clear the filters from a column on a password protected sheet.
When someone opens the shared file (from OneSite), I would like for the filters in 2 of the columns cleared but need for the sheet to stay protected as it has been messed up by others and takes some work to fix.
I am ok if the protection is cleared then the filters cleared and the protection put back with the password.
Can someone write me a code to do this?
Thank you
Apr 23 2022 07:05 AM
Here's a little example with VBA code and file...hope it helps
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.ActiveSheet.Unprotect ("1234")
If ActiveSheet.AutoFilterMode Then
If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
End If
ActiveSheet.Outline.ShowLevels RowLevels:=1, ColumnLevels:=0
ActiveWorkbook.ActiveSheet.Protect ("1234")
End Sub
It's just a bit the other way around... cancel all filters when you close it :).
Apr 25 2022 10:30 AM
Apr 25 2022 12:05 PM
Here is the code when opening the file.