Locking a cell based on tick box

MissingInAction

Board Regular
Joined
Sep 20, 2019
Messages
85
Office Version
  1. 365
Platform
  1. Windows
Good day everyone. I'm looking for VBA code that would lock a cell based on whether a check box has a tick in it, or not.
I have linked the check box to block G58. This block displays TRUE when the box is ticked. I then want block D59 to be unlocked if G58 is true and locked if G58 is false. I have tried the following code, but it does nothing:

VBA Code:
    If Target.Address = "$E$55" Then
        If ActiveSheet.Range("G58").Value = True Then
            ActiveSheet.Unprotect
            Application.ScreenUpdating = False
            Range("D59").Select
            Selection.Locked = False
            Selection.FormulaHidden = False
        Else
            ActiveSheet.Unprotect
            Application.ScreenUpdating = False
            Range("D59").Select
            Selection.Locked = True
            Selection.FormulaHidden = False
        End If
    End If

E55 has a yes/no dropdown where the employee must select "yes" in order for the tick box to appear, which is why I used the if Target.Address code.

Thank you in advance.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
The block in question (D59) has a yellow fill color, since it has a conditional format formula that will make it yellow if it is blank. I tried the following:

VBA Code:
    If Range("D59:E59").DisplayFormat.Interior.Color = 65535 Then
        ActiveSheet.Unprotect "abc123"
        Application.ScreenUpdating = False
        Range("D59").Select
        Selection.Locked = False
        Selection.FormulaHidden = False
    Else
        ActiveSheet.Unprotect "abc123"
        Application.ScreenUpdating = False
        Range("D59").Select
        Selection.Locked = True
        Selection.FormulaHidden = False
    End If

The issue with this code is, it only triggers when the cell modified. This in turn also causes the person to be unable to modify what he entered, since any value inside that cell will remove the yellow fill, which means this idea wont work.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

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