CheckBox Selection

Solved/Closed
azmiismail
Posts
17
Registration date
Thursday March 3, 2011
Status
Member
Last seen
July 20, 2011
- Apr 8, 2011 at 07:06 AM
TrowaD
Posts
2886
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
June 27, 2022
- Apr 11, 2011 at 08:53 AM
Hello,
I've got two checkboxes,CheckBox1 and CheckBox2.I would like to make only one of the checkboxes to be selected at any one time.If one become TRUE another one become FALSE and vice versa.Can somebody provide me with the VBA codes and guide me into achieving this objectives?I'm very much new with Macro and VBA codes.

Thanks

1 reply

TrowaD
Posts
2886
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
June 27, 2022
515
Apr 11, 2011 at 08:53 AM
Hi Azmiismail,

When you look at your userform in VB, right-click on Checkbox1, select view code and paste this code:
Private Sub CheckBox1_Click()
If CheckBox1 = True Then CheckBox2 = False
End Sub

Right-click on Checkbox2, select view code and paste this code:
Private Sub CheckBox2_Click()
If CheckBox2 = True Then CheckBox1 = False
End Sub

Now you will not be able to select both checkboxes; selecting one will deselect the other.

Best regards,
Trowa
0