enable checkbox based on another checkbox

Shweta

Well-known Member
Joined
Jun 5, 2011
Messages
514
Hello All,

I have a userform with 3 checkboxes. When userform initializes only one checkbox (checkbox1) is enabled and rest two are disabled. I want when user check(select) the checkbox1 then only other two checkboxes get enabled and when user check again (deselect) the checkbox1 then other two checkboxes get disabled again.

Using the following code but it is not working to make the checkboxes disabled again.

Code:
Private Sub CheckBox1_AfterUpdate()
If Me.CheckBox1.Enabled = True Then
Me.CheckBox2.Enabled = True
Me.CheckBox3.Enabled = True
ElseIf Me.CheckBox1.Enabled = False Then
Me.CheckBox2.Enabled = False
Me.CheckBox3.Enabled = False
End If
End Sub

I tried with other events also like change() and click() but facing same problem.

Thanks in advance!

Regards,
Shweta Jain
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this Sub:-
Code:
Private Sub CheckBox1_Click()
Call ck(CheckBox1)
End Sub

Private Sub CheckBox2_Click()
Call ck(CheckBox2)
End Sub

Private Sub CheckBox3_Click()
Call ck(CheckBox3)
End Sub

Sub ck(Ctrl As Object)
Dim nCtr As Control
For Each nCtr In Me.Controls
    If Not nCtr.Name = Ctrl.Name Then
        If Ctrl = True Then
            nCtr.Enabled = False
        Else
            nCtr.Enabled = True
        End If
    End If
Next nCtr
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,148
Members
453,021
Latest member
Justyna P

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