Disable checkbox on cell value

In your previous code CheckboxAirSus is still an implicit empty variable...

Try;
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ctlCheckBox     As CheckBox
    
    With Me
        Set ctlCheckBox = .CheckBoxes("CheckboxAirSus")
        ctlCheckBox.Enabled = Not .Range("G55").Value = "No"
    End With
End Sub
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Thank you, VBA newbie so learning all the time. I've amended the code to the following so the checkbox visibly looks disabled.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ctlCheckBox     As CheckBox
    With Me
        Set ctlCheckBox = .CheckBoxes("CheckboxAirSus")
        ctlCheckBox.Enabled = Not .Range("G55").Value = "No"
        If Range("G55") = "No" Then
        ctlCheckBox.Value = 2
        Else
        ctlCheckBox.Value = 0
        End If
    End With
End Sub

When I want to use this on further checkboxes I've tried this code but it doesn't work, will it only work on one?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ctlCheckBox     As CheckBox
    With Me
        Set ctlCheckBox = .CheckBoxes("CheckboxAirSus")
        ctlCheckBox.Enabled = Not .Range("G55").Value = "No"
        If Range("G55") = "No" Then
        ctlCheckBox.Value = 2
        Else
        ctlCheckBox.Value = 0
        End If
    End With
    With Me
        Set ctlCheckBox = .CheckBoxes("CheckboxCW100")
        ctlCheckBox.Enabled = Not .Range("G51").Value = "No"
        If Range("G51") = "No" Then
        ctlCheckBox.Value = 2
        Else
        ctlCheckBox.Value = 0
        End If
    End With
End Sub
 
Upvote 0
Think I see the problem, the "No" in G51 is an If statement that gives "No" if any other checkbox is ticked (only allowed to tick one). But this doesn't get recognised as a worksheet change?
 
Upvote 0
Discovered the worksheet_calculate which works, however whenever I click the checkbox it won't tick, disspears straight away using the above code?
 
Upvote 0
As in the state doesn't stay. When I take out the following code it works, is there any way to return the checkbox to 0 without it doing so when the checkbox is clicked too? Seems like a loop.

Code:
      If Range("G55") = "No" Then
        ctlCheckBox.Value = 2
        Else
        ctlCheckBox.Value = 0
        End If
 
Upvote 0
Oh I think I see what is going on. At the start of your code enter:
Code:
Application.EnableEvents = False

And at the end enter:
Code:
Application.EnableEvents = True
 
Upvote 0
This still results in the checkbox unchecking itself when clicked?

Code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
    Dim ctlCheckBox     As CheckBox
    With Me
        Set ctlCheckBox = .CheckBoxes("CheckboxCW100")
        ctlCheckBox.Enabled = Not .Range("G51").Value = "No"
        If Range("G51") = "No" Then
        ctlCheckBox.Value = 2
        Else
        ctlCheckBox.Value = 0
        End If
    End With
Application.EnableEvents = True
End Sub
 
Upvote 0
Your code says that if G51 is No then tick the checkbox, otherwise untick it. So when calc kicks-off and G51 is No, is the checkbox ticked? If so then that's exactly what your code tells it to do.

Perhaps you should explain the process in a little more detail because I'm struggling to grasp what you expect from this code.
 
Upvote 0

Forum statistics

Threads
1,216,446
Messages
6,130,690
Members
449,585
Latest member
Nattarinee

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