Lock cells with macro

antaeusguy

Board Regular
Joined
Mar 8, 2010
Messages
81
I am creating a survey form. I've inserted 2 ActiveX option buttons into the worksheet (Let's cell it OptionButton1 & OptionButton2). OptionButton1 means Yes and OptionButton2 means No.

All cells are locked with password (e.g. "ABC") and the only cell unlocked is Range("A1").

If the user click on OptionButton1 (Yes), the user needs to fill in his comments into Range("A1").

If the user click on OptionButton2 (No), the Range("A1") will be locked.

I know that I need to use the value property of the OptionButton2 (selecting it will turn to True), but I don't really know how to make the cell Range("A1") to become locked. And once OptionButton2 value turns False, it should become unlocked again.

Any help is much appreciated! :)
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Maybe this :

Code:
Private Sub OptionButton1_Change()

    With OptionButton1.Parent
        .Unprotect "ABC"
        Range("a1").Locked = Not OptionButton1
        .Protect "ABC"
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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