Macro to Select Multiple Checkboxes

normanbox

New Member
Joined
Jul 8, 2015
Messages
46
I have multiple checkboxes (ex. 10) and am wanting to create macros that selects specific checkboxes (ex. a button/macro called "Basic" selects checkboxes 1, 3, and 5). Then I would like to deselect any checkbox I desire without deselecting them all (ex. deselecting checkbox 3 but checkboxes 1 and 5 remains). I'm a novice with VBA and recording a macro doesn't seem to work. Any help you could provide is greatly appreciated.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Each of the following sets 5 checkboxes to checked

Checkboxes are on a userform
- in userform code window
VBA Code:
Private Sub UserForm_Initialize()
    CheckBox1.Value = True
    CheckBox2.Value = True
    CheckBox3.Value = True
    CheckBox4.Value = True
    CheckBox5.Value = True
End Sub

.
Checkboxes are on a worksheet
- are they Form Controls ?
- are they Active-X controls ?

VBA Code:
Sub Check_Some_Boxes_Form_Control()
    With ActiveSheet
        .Shapes("Check Box 1").ControlFormat.Value = xlOn
        .Shapes("Check Box 2").ControlFormat.Value = xlOn
        .Shapes("Check Box 3").ControlFormat.Value = xlOn
        .Shapes("Check Box 4").ControlFormat.Value = xlOn
        .Shapes("Check Box 5").ControlFormat.Value = xlOn
    End With
End Sub
VBA Code:
Sub Check_Some_Boxes_ActiveX()
    With ActiveSheet
        .CheckBox1.Value = True
        .CheckBox2.Value = True
        .CheckBox3.Value = True
        .CheckBox4.Value = True
        .CheckBox5.Value = True
    End With
End Sub
 
Upvote 0
Each of the following sets 5 checkboxes to checked

Checkboxes are on a userform
- in userform code window
VBA Code:
Private Sub UserForm_Initialize()
    CheckBox1.Value = True
    CheckBox2.Value = True
    CheckBox3.Value = True
    CheckBox4.Value = True
    CheckBox5.Value = True
End Sub

.
Checkboxes are on a worksheet
- are they Form Controls ?
- are they Active-X controls ?

VBA Code:
Sub Check_Some_Boxes_Form_Control()
    With ActiveSheet
        .Shapes("Check Box 1").ControlFormat.Value = xlOn
        .Shapes("Check Box 2").ControlFormat.Value = xlOn
        .Shapes("Check Box 3").ControlFormat.Value = xlOn
        .Shapes("Check Box 4").ControlFormat.Value = xlOn
        .Shapes("Check Box 5").ControlFormat.Value = xlOn
    End With
End Sub
VBA Code:
Sub Check_Some_Boxes_ActiveX()
    With ActiveSheet
        .CheckBox1.Value = True
        .CheckBox2.Value = True
        .CheckBox3.Value = True
        .CheckBox4.Value = True
        .CheckBox5.Value = True
    End With
End Sub
Thank you. That worked perfectly!
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

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