Checkbox Click

T

txw3

....

I have a 2 checkboxes in excel, captioned yes and no. How can I ge
these to check when clicked upon. Both begin unchecked. If one i
checked the other is not.

Thank you
 
T

Tom Ogilvy

Option buttons are designed to operate this way. Why not use two Option
buttons.
 
Joined
Oct 17, 2007
Messages
6
Reaction score
0
There are two ways you can do this...

One would be to include the following...

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

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



Or you can use the following... (better)

Enter in Module1 of the workbook...

Public Sub SingleCheckbox(OnSheet As Worksheet, ThisControl As Object)
'
' Uncheck any other checkboxes with the
'
Dim oleTemp As OLEObject

If ThisControl.Object.Value Then
For Each oleTemp In OnSheet.OLEObjects
If TypeName(oleTemp.Object) = "CheckBox" Then
If oleTemp.Object.GroupName = ThisControl.Object.GroupName Then
If oleTemp.Name <> ThisControl.Name Then
oleTemp.Object.Value = False
End If
End If
End If
Next
End If

End Sub



And this code in the click event of each control. Modify the 2nd argument to be the correct control.

Private Sub CheckBox1_Click()

SingleCheckbox ActiveSheet, CheckBox1

End Sub
 

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