check/uncheck a checkbox

L

leonidas

Hi,

I have two checkboxes on a userform in Excel, "Yes" and "No".
When the userform is opened the checkboxes are both unchecked.
When the "Yes" checkbox is checked and I then check the "No" checkbox,
the "Yes" checkbox should be unchecked again.
When the "No" checkbox is checked and I then check the "Yes" checkbox,
the "No" checkbox should be unchecked again.
I have some code below, but it doesn't work.
Can someone help me solve this problem? Thanks in advance!


Code:
--------------------
Private Sub CheckBox1_Click()

CheckBox1.Value = True
CheckBox2.Value = False

End Sub
--------------------

-------------------------------------------------------------------------

Code:
--------------------
Private Sub CheckBox2_Click()

CheckBox2.Value = True
CheckBox1.Value = False

End Sub
 
C

colofnature

You'd be better off using OptionButtons rather than CheckBoxes - they'r
mutually exclusive by design so when you click one the other i
deactivated.

Co
 
P

Paul Lautman

leonidas said:
Hi,

I have two checkboxes on a userform in Excel, "Yes" and "No".
When the userform is opened the checkboxes are both unchecked.
When the "Yes" checkbox is checked and I then check the "No" checkbox,
the "Yes" checkbox should be unchecked again.
When the "No" checkbox is checked and I then check the "Yes" checkbox,
the "No" checkbox should be unchecked again.
I have some code below, but it doesn't work.
Can someone help me solve this problem? Thanks in advance!


Code:
--------------------
Private Sub CheckBox1_Click()

CheckBox1.Value = True
CheckBox2.Value = False

End Sub
--------------------

-------------------------------------------------------------------------

Code:
--------------------
Private Sub CheckBox2_Click()

CheckBox2.Value = True
CheckBox1.Value = False

End Sub
--------------------

Why not change them to radio buttons, they do this naturally.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top