Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to select one checkbox and deselect the other checkbox? (VBA required)

I have 2 checkboxes, what i want to do is when i select one, the other 1 will be deselected, which means user will not have the ability to select it the other checkbox. I was wondering if it is possible to do so?

like image 385
user1204868 Avatar asked Dec 13 '25 01:12

user1204868


1 Answers

Yes it is possible. But why not use an option button instead?

Anyways to answer your query.

Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
        CheckBox2.Value = False
        CheckBox2.Enabled = False
    Else
        CheckBox2.Enabled = True
    End If
End Sub

Private Sub CheckBox2_Click()
    If CheckBox2.Value = True Then
        CheckBox1.Value = False
        CheckBox1.Enabled = False
    Else
        CheckBox1.Enabled = True
    End If
End Sub

FOLLOWUP

Thanks for the fast update! what is the difference between a checkbox and option button? I thought they do the same thing? – user1204868 48 secs ago

Excel VBA Option Buttons (Also known as radio buttons) are the same as Check Boxes except that Option Buttons are dependent on each other while Check Boxes are not. When you check one Option Button the other Option Button will automatically get unchecked.

See the snapshot below on how they look :)

Would recommend seeing the Excel's inbuilt VBA help for more details ;)

SNAPSHOT:

enter image description here

HTH

Sid

like image 105
Siddharth Rout Avatar answered Dec 14 '25 20:12

Siddharth Rout



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!