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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,450
Try something like this...
Code:
ActiveSheet.Protect Password:="c"[COLOR="Red"], _[/COLOR]
        DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True
 

CMSS

New Member
Joined
Jul 29, 2010
Messages
18
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.
 

CMSS

New Member
Joined
Jul 29, 2010
Messages
18
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:

CMSS

New Member
Joined
Jul 29, 2010
Messages
18
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?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,043
Messages
5,835,099
Members
430,341
Latest member
kelstnmate

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
Top