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?
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:

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