Protected Worksheet: All cells except 1 need to be locked

gingersnaps212

New Member
Joined
Jul 27, 2010
Messages
9
I have a worksheet in which a user selects from a drop down list and from there everything else is filled out. In order to protect this and prevent users from messing up the form (thus preventing numerous headaches for me), I want to lock all cells except for this one cell containing the drop down list.

Below is the code I have:
With Sheets("Spreadsheet")
.Unprotect Password:="PSWHere"
.Cells.Locked = True
.Range("G8").Locked = False
.Protect Password:="PSWHere"
End With

But, I am getting the following error:
Run-time error 1004: Unable to set the Locked property of the Range class

I am using Excel 2003 and VB 6.5. Any help and/or suggestions would be greatly appreciated.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi,

How I understand you want to lock all cells except “G8”, if so then this macro will work for you.
Code:
Sub Macro1()
    With Sheets("Spreadsheet")
        .Unprotect Password:="PSWHere"
        .Cells.Locked = True
        .Range("G8").Locked = False
        .Protect Password:="PSWHere"
    End With
End Sub
 
Upvote 0
Hi,

How I understand you want to lock all cells except “G8”, if so then this macro will work for you.
Code:
Sub Macro1()
    With Sheets("Spreadsheet")
        .Unprotect Password:="PSWHere"
        .Cells.Locked = True
        .Range("G8").Locked = False
        .Protect Password:="PSWHere"
    End With
End Sub


This is exactly what I have already written as the code and I get the above mentioned 1004 error
 
Upvote 0
Are you sure that it isn't erroring in another part of the macro? Try temporarily removing those exact lines of code and running the macro to see if it still gets the error.
 
Upvote 0
Are you sure that it isn't erroring in another part of the macro? Try temporarily removing those exact lines of code and running the macro to see if it still gets the error.

I have removed the .Range("G8").Locked = False and the macro runs perfectly.
 
Upvote 0
Your code runs fine for me, but with all these cells "locked", unless everything else is a formula, how is the SS going to update automatically?

lenze
 
Upvote 0
Your code runs fine for me, but with all these cells "locked", unless everything else is a formula, how is the SS going to update automatically?

lenze

Everything else is updated via macro that is run when a selection is clicked in that cell.
 
Upvote 0
Everything else is updated via macro that is run when a selection is clicked in that cell.
And it works?? This will error out
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$G$8" Then Exit Sub
Select Case Target
Case "OK": Range("$A$1") = "OK"
Case Else:
End Select
End Sub

lenze
 
Upvote 0

Forum statistics

Threads
1,215,626
Messages
6,125,896
Members
449,271
Latest member
bergy32204

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