PDA

View Full Version : [SOLVED] Need Help Trying to Unlock Certain Cells



hermit14
06-09-2009, 06:02 AM
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

lucas
06-09-2009, 06:33 AM
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

hermit14
06-09-2009, 09:15 AM
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!

lucas
06-09-2009, 09:21 AM
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.