Disable checkbox in VBA

ElvisSteel

Board Regular
Joined
Mar 23, 2009
Messages
122
I have a sheet with a number of checkboxes, and I need to conditionally enable/disable some of them.
For example, if the user checks Box1, then the question for Box2 becomes relevant and Box2 becomes available. If Box1 is unchecked, Box2 needs to be unchecked and disabled.
Is this possible and if so, can you please advise how.
Thanks

Steve
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi Steve

There is an event for handling just this

try:

Code:
Private Sub CheckBox1_Change()
Select Case CheckBox1.Value
    Case True: CheckBox2.Enabled = True
    Case False: CheckBox2.Enabled = False
End Select
End Sub

As an example.
 
Upvote 0
To uncheck the box also just add...

Code:
Private Sub CheckBox1_Change()
Select Case CheckBox1.Value
    Case True: CheckBox2.Enabled = True
    Case False: CheckBox2.Enabled = False: CheckBox2.Value = False
End Select
End Sub
 
Upvote 0
Sorry I was a little premature with the reply, as I cannot get the code you suggested to work.

I am not using a form, just a checkbox on the worksheet. Is there a CheckBox_Change event, and if so, where do I put the code?

Am I missing something obvious?
 
Upvote 0
Depends on the type of checkbox it is. Did you add it from the controls toolbox or from the forms toolbar?
 
Upvote 0
Forms controls don't have event handlers, so you will have to do the enabling/disabling from the procedure you assign to it.
 
Upvote 0
OK thanks, but can I still enable/disable a checkbox from within the procedure?
I have assigned a macro (CheckBox1_Click)to the checkbox, and linked it to a cell ("Box1Value")

The following code gives "Run time error 424, Object required"...


Sub CheckBox1_Click()
Select Case Range("Box1Value").Value
Case True: CheckBox2.Enabled = True
Case False: CheckBox2.Enabled = False: CheckBox2.Value = False
End Select
End Sub
 
Upvote 0
Try:
Code:
Sub CheckBox1_Click()
Activesheet.Checkboxes("CheckBox2").Enabled = Range("Box1Value").Value
End Sub
<!-- / message -->
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,343
Members
449,155
Latest member
ravioli44

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