Userform CheckBox question.

dbmathis

Well-known Member
Joined
Sep 22, 2002
Messages
1,064
Hi all,

I looked through the forums and didn't seem to fin anything like what I am trying to do.

I have 21 CheckBoxes. Named CheckBox1 - CheckBox21..

I need a macro the will do the following:

When any of the CheckBoxes within CheckBox1 - CheckBox21 is clicked / checked then all other checkboxes are greyed out / disabled but the one that was checked?

The what code can I use on my commandbutton to enable them all back at a later time?

Thanks.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
When do you want this to occur?

Whenever a checkbox is clicked?

If you do then what you probably need is a class module.

I'll try and rustle something up and post back.

By the way why not just use option buttons?
 
Upvote 0
Right this is what I came up with.

When you click a checkbox then it disables all the rest.

When you click it again it re-enables all the checkboxes.

In a Class module called CCheckBoxes put this code.
Code:
Option Explicit

Public WithEvents CheckGroup As MSForms.CheckBox

Private Sub CheckGroup_Click()
Dim ctl As MSForms.Control

    For Each ctl In UserForm1.Controls
        If CheckGroup.Value Then
            ctl.Enabled = ctl.Caption = CheckGroup.Caption
        Else
            ctl.Enabled = True
        End If
    Next ctl
End Sub
In the userform module put this code.
Code:
Option Explicit

Dim CheckBoxes() As New CCheckBoxes

Private Sub UserForm_Initialize()
Dim ctl As MSForms.Control
Dim I As Long
    For Each ctl In Me.Controls
        If TypeName(ctl) = "CheckBox" Then
            I = I + 1
            ReDim Preserve CheckBoxes(1 To I)
            Set CheckBoxes(I).CheckGroup = ctl
        End If
    Next
End Sub
 
Upvote 0
What is the difference, other than apperence, between the optionbox and the check box?
 
Upvote 0
You can only pick one option button out of a group.

To group option buttons together use the GroupName property, which can easily be set by selecting all the option buttons for the group.
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,499
Members
449,089
Latest member
Raviguru

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