Lock / Unlock cells depending on True / False

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,

I'm not sure why this code isn't working. Can someone tell me if I'm missing a trick please?

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A17") = "TRUE" Then
Range("F17:K17").Locked = False
ElseIf Range("A17") = "FALSE" Then
Range("F17:K17").Locked = True
End If
End Sub

Thank you!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi there, locking cells doesn't actually fully lock them as you'd expect unless you protect the sheet. You'd have to add in something like this:

Code:
Worksheets(1).Protect
 
Upvote 0
Hi. I appreciate what you are saying and I was going to deal with the protection side later.
I was however expecting my code to tick/untick the Protection box under Format Cells but it's not doing that. Are you saying it can't do this unless I deal with the protection side first?
 
Upvote 0
How is A17 being changed?
If being changed manually, or via data validation, remove the quotes from True & false.
 
Upvote 0
A17 is linked to a Check Box. If it's ticked A17 reads TRUE, if un-ticked FALSE.
I had tried removing the quotations but that didn't work.
 
Upvote 0
It doesn't appear to even like the code being in there.
It returns;
Compile Error: Ambiguous name detected: Worksheet_Change
 
Upvote 0
That error shows that you have two (or more)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
events in the same module, which you cannot have.
However change events do not recognise changes that occur due to a Checkbox being clicked.
You will need to link the code to the check box.
Are your checkboxes form controls or ActiveX
 
Upvote 0
Thank you! Understood. They are currently form controls but I gather I'd need to use ActiveX.
I may re-think this all entirely though.
 
Upvote 0
ActiveX won't make any difference, they still wont trigger a change event.
Do you just have the one checkbox, or multiple checkboxes?
 
Upvote 0
I've decided to try and work something with Data Validation to highlight when they haven't selected the check box/period ending date if they're entering data in that row.

However, if you don't mind, is there any chance you could help me another query I have. I've titled it "Combine VBA Codes together" :)
 
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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