Macro to password protect and allow autofilter

  • Thread starter Thread starter NStarch
  • Start date Start date
N

NStarch

I am looking for a macro to set up a protection that only allows someone to
use the AutoFilter. The protection needs to set up a password for all the
sheets at once.

I am also wanting a macro to select all of the sheets and remove the
password.
 
Each sheet must have Autofilter enabled before protecting.

Sub auto_open()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
With ws
.Protect Password:="justme", userinterfaceonly:=True
.EnableAutoFilter = True
End With
Next ws
End Sub

To unprotect all sheets at once.........

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Unprotect Password:="justme"
Next N
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP
 
Back
Top