I need a simple VBA code to lock the cell (or cell range) if i click on a checkbox
eg - If i click on a checkbox, the cell range eg A1:A20 should be unlocked and then i can enter some values; if i deselect the checkbox the cell should be locked
Some one can help me with the code.Its throwing me an error "Unable to Set the Locked Property of the Range Class"
Try this (using ActiveX Checkbox
):
Private Sub CheckBox1_Click()
Dim rng As Range
Set rng = Worksheets("Sheet1").Range("A1:A20")
ActiveSheet.Unprotect ""
If Me.CheckBox1.Value Then
rng.Locked = False
rng.Interior.Color = RGB(255, 255, 255)
Else
rng.Locked = True
rng.Interior.Color = RGB(220, 220, 220)
End If
ActiveSheet.Protect ""
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.