Forum

Macro to Select Pro...
 
Notifications
Clear all

Macro to Select Protection Options

3 Posts
2 Users
0 Reactions
125 Views
(@paul_f)
Posts: 81
Estimable Member
Topic starter
 

I have the following code assigned to an object:

ActiveSheet.Unprotect Password:="EIS 2017"

Range("G5:L5").Select

Selection.EntireColumn.Hidden = False

Range("L5").Select

ActiveSheet.Protect AllowSorting:=True, AllowFiltering:=True

ActiveSheet.Protect Password:="EIS 2017"

End Sub

This works fine, but when I enable protection, the only options I want to be selected are Sort and Use Autofilter, nothing else. The macro above clears every checkbox in the Worksheet Protection dialog box upon execution. What is wrong here?

Paul

 
Posted : 13/10/2020 5:09 pm
(@purfleet)
Posts: 412
Reputable Member
 

Sorting

I think that you can only sort on unprotected cells, which is kind of logical as you are changing them - although not really helpfull in this situation.

Autofilter

I dont think you can turn on the autofilter with protection, but you can allow the user to use the auto filter if it is already there

You also need all the protection options on one row otherwise the second one will over write the first one.

Sub Macro31()
'
' Macro31 Macro
'
'ActiveSheet.Unprotect
'
ActiveSheet.Unprotect Password:="EIS 2017"
Range("G5:L5").Select
If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False

Range("d11:f11").AutoFilter

Selection.EntireColumn.Hidden = False

Range("L5").Select

ActiveSheet.Protect Password:="EIS 2017", AllowSorting:=True, AllowFiltering:=True

End Sub

As an option, you could add a button to the worksheet which would let the VBA do the sorting (see attached). Not sure on your sheet if this is fesible but could be an option

 
Posted : 15/10/2020 4:49 am
(@paul_f)
Posts: 81
Estimable Member
Topic starter
 

Thanks! I think the issue here was putting the protection code on two lines. This did the trick:

ActiveSheet.Protect Password:="EIS 2017", AllowSorting:=True, AllowFiltering:=True
 
Posted : 15/10/2020 6:08 pm
Share: