PDA

View Full Version : Check Box Issue



c7015
06-05-2012, 10:58 AM
Hey Guys , I have a small issue ,

I have 6 check boxes confusingly named optionbutton1 -> optionbutton6

they are on a user form that when checked selects a range to be graphed....

this all works fine , but I want to write an if then statement that says if any 2 optionbuttons (1 to 6 only) are checked then

'do this code

end


but I don't want to go thru all the variables if I don't have to

is there a line of code that works to say if more then one check box is selected then ...

'do this code


end / thread

Kenneth Hobs
06-05-2012, 11:39 AM
Private Sub optionbutton1_Click()
MsgBox CheckBoxesChecked("OptionButton", 6)
End Sub

Private Function CheckBoxesChecked(prefix As String, count As Integer) As Integer
Dim i As Integer, ii As Integer
ii = 0
For i = 1 To count
If Me.Controls(prefix & i).Value = True Then
ii = ii + 1
End If
Next i
CheckBoxesChecked = ii
End Function

c7015
06-05-2012, 11:52 AM
thanks Ken

will try it out ,

I had used this a temp fix and it seems to work thou not as pretty as yours If optionbutton1.Value = True Then
a = 1
End If

If optionbutton2.Value = True Then
b = 1
End If

If optionbutton3.Value = True Then
c = 1
End If

If optionbutton4.Value = True Then
d = 1
End If


If Optionbutton5.Value = True Then
e = 1
End If

If optionbutton6.Value = True Then
f = 1
End If

If a + b + c + d + e + f = 2 Then