#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Select case

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select case

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

--
Regards,
Tom Ogilvy

"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




  #3   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select case Hein Excel Discussion (Misc queries) 2 October 22nd 08 07:06 AM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Case Select Bill Excel Programming 10 January 8th 05 05:02 PM
Need help on Select Case Susan Hayes Excel Worksheet Functions 1 November 3rd 04 10:25 PM
select case help please Christine Flott[_2_] Excel Programming 4 July 29th 03 09:05 PM


All times are GMT +1. The time now is 06:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"