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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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