Quick way to disable all other checkboxes on form (except the one that's ticked)?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
270
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have this clunky code:
VBA Code:
Private Sub CheckBox1_Change()

Select Case CheckBox1.Value
    Case True
        CheckBox2.Enabled = False
        CheckBox3.Enabled = False
        CheckBox4.Enabled = False
        CheckBox5.Enabled = False
        CheckBox6.Enabled = False
        CheckBox7.Enabled = False
        CheckBox8.Enabled = False
        CheckBox9.Enabled = False
        CheckBox10.Enabled = False
        CheckBox11.Enabled = False
        CheckBox12.Enabled = False
        cbSubmit.Enabled = True
    Case Else
        CheckBox2.Enabled = True
        CheckBox3.Enabled = True
        CheckBox4.Enabled = True
        CheckBox5.Enabled = True
        CheckBox6.Enabled = True
        CheckBox7.Enabled = True
        CheckBox8.Enabled = True
        CheckBox9.Enabled = True
        CheckBox10.Enabled = True
        CheckBox11.Enabled = True
        CheckBox12.Enabled = True
        cbSubmit.Enabled = False

End Select

End Sub

Is there a quicker way? There are twelve checkboxes on the form so I'm going to have one of these for each one - plus, there may come a time when more checkboxes are introduced so I'm going to have to rewrite all of this.

Thanks in advance as always.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
As an idea, try following & see if does what you want

VBA Code:
Sub EnableCheckBox(ByVal objCheckBox As Object)
    Dim i           As Long
   
    For i = 1 To 12
        With Me.Controls("CheckBox" & i)
            If .Name <> objCheckBox.Name Then .Enabled = Not objCheckBox.Value
        End With
    Next i
    Me.cbSubmit.Enabled = objCheckBox.Value
End Sub

call by passing the required checkbox object

VBA Code:
Private Sub CheckBox1_Click()
    EnableCheckBox CheckBox1
End Sub

Private Sub CheckBox2_Click()
    EnableCheckBox CheckBox2
End Sub

Dave
 
Upvote 0
Solution
If you only want one selectable, using Optionbuttons is easier since that's how they work natively.
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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