Allow autofilter when protecting all sheets in a workbook

rugby_nut

New Member
Joined
Jan 13, 2009
Messages
42
Hi all,
I'm using the code below to lock and unlock all sheets in a workbook. I require users to use slicers and/or filter data in tables within the sheets. I have removed protection from the slicers, but I can't figure out how to allow the autofilter for all sheets when protecting all sheets at once. Any help would be great. Thanks.
------------------------------------------------------------------------------------
' Protect All Worksheets
Sub ProtectAllSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Protect "Password"
Next ws

End Sub
--------------------------------------------------------------------------------------
' UnProtect All Worksheets
Sub UnProtectAllSheets()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Unprotect "Password"
Next ws

End Sub
-----------------------------------------------------------------------------------------
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
You would want to set the user interface property

VBA Code:
ws.Protect Password:="Password", UserInterfaceOnly:=True, AllowFiltering:=True
 
Upvote 0
Solution
Hi dave3009,
Thank you for the reply. I've tried this and it doesn't seem to work with tables. I tried the code using data that is not in a table and it works fine. But it seems it doesn't work when trying to filter a table. Is there anything different when using tables?
 
Upvote 0
Hi dave3009,
Apologies, not sure what happened, or whether I had too many workbooks open. But when I closed everything down and started afresh, everything works just fine! Thank you for your help.

Note to self.......Make changes to one workbook at a time :)
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top