Can a checkbox uncheck another one?

EtienneD

New Member
Joined
Jul 21, 2022
Messages
27
Office Version
  1. 2016
Platform
  1. Windows
I have multiple checkboxes acting as options for the user, and some of those options can't be chosen together. So is it possible to use vba so that when CHECKBOX1 is checked than CHECKBOX2 would be unchecked?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Better to use option buttons. By design, choosing one deselects any previously chosen one (if there was one). The direct answer to your question is yes, code can do that, but you can avoid it altogether. Do you have to use checkboxes? Or is this just about box1 vs box2 and you want to have the ability to keep 3,4,5 etc. still checked?

And if 2 is unchecked when 1 is checked, is 1 unchecked when 2 is checked?
 
Upvote 0
Set the two checkboxes in the same GroupName.
1670383035638.jpg

Try to press Alt L D M in sequence to enable the Design Mode.
Then double-click the Button and you should find the GroupName above.
 
Upvote 0
try this
The code should be put in the sheet with the CheckBoxes, not in Module.
VBA Code:
Private Sub CheckBox1_Click()
    If CheckBox1 = True Then
        CheckBox2 = False
        CheckBox2.Enabled = False
    End If
    If CheckBox1 = False Then
        CheckBox2.Enabled = True
    End If
End Sub
 
Upvote 0
No apologies necessary. If anyone is good at making that sort of mistake, it's me! ;)
 
Upvote 0

Forum statistics

Threads
1,215,334
Messages
6,124,323
Members
449,154
Latest member
pollardxlsm

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