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
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,271
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?
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,780
Messages
5,513,400
Members
408,950
Latest member
bndouglas

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top