Macro to password protect and allow autofilter

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.
 
G

Gord Dibben

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top