Consulting

Results 1 to 4 of 4

Thread: Need Help Trying to Unlock Certain Cells

  1. #1
    VBAX Newbie
    Joined
    Jun 2009
    Posts
    2
    Location

    Need Help Trying to Unlock Certain Cells

    Hi everyone. I'm new to this forum, but could use some help. I have written a program where I want to password protect certain sheets that have macros running on them, but need to be able to let the user input values in certain cells. I am trying to set up a range of cells to be unlocked and then password protect the rest of the sheet. It worked the first time I put the code in, but since then whenever I run the program I get the following error:

    "Run time error '1004' - Unable to set the Locked property of the Range class."

    Here is the code I put for this on the 'Main Inputs':

    Worksheets("Main Inputs").Activate
    Sheets("Main Inputs").Range("C3:C56").Locked = False
    Sheets("Main Inputs").Protect Password:="ab", _
    DrawingObjects:=False, UserInterFaceOnly:=True
    Any help on this would be appreciated. Thanks!

    hermit14

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    maybe this will work better:
    Option Explicit
    Sub a()
    With Sheets("Main Inputs")
    .Range("C3:C56").Locked = False
    .Protect Password:="ab", _
    DrawingObjects:=False, UserInterFaceOnly:=True
    End With
    End Sub
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Newbie
    Joined
    Jun 2009
    Posts
    2
    Location
    Thanks for the help Steve. I tried the code you suggested and it worked after adding two more lines of code:

    With Sheets("Main Inputs")
            .Unprotect Password:="ab"
            .Cells.Locked = True
            .Range("C3:C56").Locked = False
            .Protect Password:="ab", _
            DrawingObjects:=True,  UserInterFaceOnly:=True
    End With
    Thanks Again!

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    glad you got it working. Be sure to mark your thread solved using the thread tools at the top of the page. This saves people from reading through the thread just to find it has been resolved.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •