Vba - protection & filtering

moni_tm

New Member
Joined
Nov 4, 2015
Messages
29
Hello,

I have the following code which i have to protect my workbook and allow filtering.

Code:
Sub ProtectSheets()
Dim wsheet As Worksheet

For Each wsheet In ActiveWorkbook.Worksheets

If wsheet.NAME <> "TB - EPM" And wsheet.NAME <> "ACT - GLORY" And wsheet.NAME <> "ACT - BARC" And wsheet.NAME <> "ACT - 3C" _
And wsheet.NAME <> "MHGL" Then

wsheet.Protect Password:="12345", UserInterfaceOnly:=True, AllowSorting:=True, AllowFiltering:=True

Else
End If

Next wsheet
End Sub

If I open my unprotected workbook and run this protection code, I am allowed to use autofilters which I have setup as buttons. If I close my protected workbook and then reopen, I am then not allowed to use the macro autofilter buttons, I need to unprotect the workbook - I can protect it straight away and all is normal again.

At the moment I have set the workbook to unprotect on close and protect on open but is this necessary?

As always, any help greatly appreciated.

Tom
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,215,884
Messages
6,127,565
Members
449,385
Latest member
KMGLarson

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