Thread: Select case
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Select case

One way of doing that:

Private Sub CommandButton1_Click()

Dim i As Byte

On Error Resume Next
For i = 1 To 5
If Controls("OptionButton" & i).Value = True Then
Exit For
End If
Next
On Error GoTo 0

Select Case i
Case 1
MsgBox "option button " & i & " ticked"
Case 2
MsgBox "option button " & i & " ticked"
Case 3
MsgBox "option button " & i & " ticked"
Case 4
MsgBox "option button " & i & " ticked"
Case 5
MsgBox "no option button ticked"
End Select

End Sub

RBS


"Sandy" wrote in message
...
I have four option boxes on a spreadsheet.The following code works fine but
I'd like to have it working in select case, but I don't know how to do it,
any offers?

Private Sub options()
If opt1.Value = True Then
MsgBox ("You chose A")
ElseIf opt2.Value = True Then
MsgBox ("You chose B")
ElseIf opt3.Value = True Then
MsgBox ("You chose C")
ElseIf opt4.Value = True Then
MsgBox ("You chose D")
Else: MsgBox ("You didn't choose any")
End If
End Sub

Sandy