Checkbox Click

  • Thread starter Thread starter txw3
  • Start date Start date
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
 
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
 
Back
Top