LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Form - Get Selected (true) value of Option Button

You could use something like this...

Private Sub CommandButton1_Click()
Dim OB As msforms.OptionButton
Dim SelectedOB As msforms.OptionButton
On Error Resume Next
For Each OB In Controls
If TypeOf OB Is msforms.OptionButton Then
If OB.GroupName = "MyGroupName" Then
If OB.Value = True Then
Set SelectedOB = OB
Exit For
End If
End If
End If
Next
'
' Your code would go here instead of what follows. Use the SelectedOB
' object to get the Name, Caption or whatever other property of the
' selected OptionButton you may want to use
'
If Err.Number 0 Then
MsgBox "No OptionButton selected"
Else
MsgBox SelectedOB.Name & " -- " & SelectedOB.Caption
End If
End Sub

--
Rick (MVP - Excel)


"MM User" wrote in message
...
Hi,

I have a form that contains several option buttons (all are in the same
groupname), I would like to make this easier to manage so is it possible
to that after the user has selected a option button and clicked the OK
button to search the form for which option button is selected ? this way I
could use a case statement.

Thanks in advance.


 
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
option button (Form) George Excel Programming 2 March 8th 07 03:01 AM
Option Button - multiple selected alanap Excel Worksheet Functions 1 April 17th 06 11:04 PM
If option button not selected Hywel[_2_] Excel Programming 2 November 8th 05 09:32 AM
Having a macro recognize when an option button has been selected Linking to specific cells in pivot table Excel Programming 3 August 26th 05 05:21 PM
Difficulties in VBA ( User form and option button) paradise Excel Programming 2 October 28th 03 01:11 PM


All times are GMT +1. The time now is 02:06 AM.

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"