Check and clear Multiple check boxes

D

Dean

I have about 20 check boxes on sheet1 of a spreadsheet from the Controls tool
box.
5 of them are loners and should not be touched in regard to the remaining 15.
The 15 are Very good, Good, Ok, Bad, Very Bad answers...
Q1 A1,2,3,4,5
Q2 A1,2,3,4,5
Q3 A1,2,3,4,5

I want to be able be click an answer on Q1 and have the code untick all the
other answers for Q1 but not Q2 or Q3, then tick any one of the answers on Q2
and have the code untick all the other boxes on Q2 and same for Q3.
If however the user changes their mind on Q? the code should untick all the
other answers on that Q.

I have (at work) some working code but checking through it on Debug, step
into it jumps backwards and forwards through each of the checkbox?_click()
subs.

Can someone suggest some code to do the above please?

Thanks
Dean
 
G

Gary Brown

Example assumes there are 3 checkboxes...
When Checkbox1 is checked/unchecked, checkboxes 2 & 3 are unchecked.
Do the Same type of procedure with checkboxes 2 & 3.

Private Sub CheckBox1_Click()
CheckBox2.Value = False
CheckBox3.Value = False
End Sub
 
R

ryguy7272

This will clear all CheckBoxes:
Sub ClearCheckBoxes()
Dim ChkBox As Object
For Each ChkBox In ActiveSheet.CheckBoxes
ChkBox.Value = xlOff
Next ChkBox
End Sub


This will clear all ActiveX CheckBoxes:
Sub UnCheckBoxesActiveX()
Dim objChkBox As OLEObject
With Sheets("Clear All Check Boxes")
For Each objChkBox In .OLEObjects
If TypeName(objChkBox.Object) = "CheckBox" Then
objChkBox.Object.Value = False
End If
Next
End With
End Sub

Modify to suit.
 
D

Dean

Ryan, this will clear all the check boxes. I only want the five related to
each question clearing.

Gary,this is the code I currently use and it seams that it is re-checking
each checkbox when they are changed.
the code is in the "Click" event. When I click A1 it clears A2,A3,A4,A5 but
runs the code in A2, A3, A4, A5 as if I had clicked them.

Dean
 
G

Gary Brown

When you click on CheckBox1 and it does something to Checkbox2, the Change
AND Click methods in CheckBox2 fire up. You have to work your code around
that situation.
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown
 

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