VBA Excel 2007 Changing Protection Parameters

CMSS

New Member
Joined
Jul 29, 2010
Messages
18
I am using macros with a worksheet that is protected. I unprotect it and run the macro, but when I try to re-protect it, my parameters are reset. I have tried writing the code to specify the parameters, but I receive a syntax error. Here is my protection code:

Code:
ActiveSheet.Protect Password:="c"
        DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try something like this...
Code:
ActiveSheet.Protect Password:="c"[COLOR="Red"], _[/COLOR]
        DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True
 
Upvote 0
That solved the problem, but created a new one. Now it leaves the sheet unprotected. Cells can be manipulated, cleared, and data added to them. I want to only be able to select cells, but not change them, and sort them.
 
Upvote 0
Now I have changed the coding so that the sheet is protected, but it won't allow the data to be sorted, even though I have the parameters set to allow it. Here is what I have:

Code:
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
 
 
    Sheets("Data Collector").Unprotect Password:="c"
    Sheets("Session Archive").Unprotect Password:="c"
    Sheets("Data Collector").Range("A2:X2").Copy
    Sheets("Session Archive").Cells(Rows.Count, "A").End(xlUp)(2).Offset(0, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Sheets("Session Archive").Protect Password:="c", _
        DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowSorting:=True
 
Last edited:
Upvote 0
I want the worksheet to be protected, but sortable. I don't want to be able to change the contents of the cells, but are you saying the cells have to be unprotected to be sorted?
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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