Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Grouped option buttons on forms
This should be easy...how does one determine which of a set of grouped
option buttons is selected? Let's say I have 4 option buttons (optionbutton1, optionbutton2, etc) with groupname set to Season. The user selects....winter, which corresponds to optionbutton4. I can check each one... If Userform1.OptionButton1.Value = -1 Then x = 1 If Userform1.OptionButton2.Value = -1 Then x = 2 If Userform1.OptionButton3.Value = -1 Then x = 3 If Userform1.OptionButton4.Value = -1 Then x = 4 but there MUST be a better way!! I have many groups and many, many option buttons on my form. The above solution quickly becomes tedious. Thanks, John |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Grouped option buttons on forms
Dim c As Control
Dim x As Integer For Each c In UserForm1.Controls If c.GroupName = "Season" And c.Value = True Then x = Right(c.Name, Len(c.Name) - 12) End If Next c Hth, Merjet |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Grouped option buttons on forms
for i = 1 to 4
set ctrl = me.controls("OptionButton" & i) if ctrl.Value then x = i exit for end if next There is no me.Groups(groupname).Value that will tell you the name of the optionbutton or anything like that. -- regards, Tom Ogilvy " wrote: This should be easy...how does one determine which of a set of grouped option buttons is selected? Let's say I have 4 option buttons (optionbutton1, optionbutton2, etc) with groupname set to Season. The user selects....winter, which corresponds to optionbutton4. I can check each one... If Userform1.OptionButton1.Value = -1 Then x = 1 If Userform1.OptionButton2.Value = -1 Then x = 2 If Userform1.OptionButton3.Value = -1 Then x = 3 If Userform1.OptionButton4.Value = -1 Then x = 4 but there MUST be a better way!! I have many groups and many, many option buttons on my form. The above solution quickly becomes tedious. Thanks, John |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Grouped option buttons on forms
Got it.....thanks guys.
JH On Feb 12, 2:59 pm, Tom Ogilvy wrote: for i = 1 to 4 set ctrl = me.controls("OptionButton" & i) if ctrl.Value then x = i exit for end if next There is no me.Groups(groupname).Value that will tell you the name of the optionbutton or anything like that. -- regards, Tom Ogilvy |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Grouped option buttons on forms
On Feb 12, 2:58 pm, "merjet" wrote:
Dim c As Control Dim x As Integer For Each c In UserForm1.Controls If c.GroupName = "Season" And c.Value = True Then x = Right(c.Name, Len(c.Name) - 12) End If Next c Hth, Merjet I spoke too soon....I want to check each by GroupName and Value, but c.GroupName is not valid. Only OptionButtons have GroupNames, controls do not. So I tried: Dim o As OptionButton DrngPied.Show 'DrngPied is the form For Each o In DrngPied.Controls If o.GroupName = "SizeOptions" And o.Value = -1 Then sSize = c.Name End If Next o but I get a Type Mismatch at the For Each line. John |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Grouped option buttons on forms
Dim c As Control
Dim x As Integer For Each c In UserForm1.Controls if typeof c is MSForms.OptionButton then If c.GroupName = "Season" And c.Value = True Then x = Right(c.Name, Len(c.Name) - 12) End If End If Next c -- Regards, Tom Ogilvy wrote in message ups.com... On Feb 12, 2:58 pm, "merjet" wrote: Dim c As Control Dim x As Integer For Each c In UserForm1.Controls If c.GroupName = "Season" And c.Value = True Then x = Right(c.Name, Len(c.Name) - 12) End If Next c Hth, Merjet I spoke too soon....I want to check each by GroupName and Value, but c.GroupName is not valid. Only OptionButtons have GroupNames, controls do not. So I tried: Dim o As OptionButton DrngPied.Show 'DrngPied is the form For Each o In DrngPied.Controls If o.GroupName = "SizeOptions" And o.Value = -1 Then sSize = c.Name End If Next o but I get a Type Mismatch at the For Each line. John |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Grouped option buttons on forms
Maybe...
Dim o As Control drngPied.Show For Each o In drngPied.Controls If TypeOf o Is MSForms.OptionButton Then If o.GroupName = "SizeOptions" And o.Value = -1 Then sSize = c.Name End If End If Next o wrote: On Feb 12, 2:58 pm, "merjet" wrote: Dim c As Control Dim x As Integer For Each c In UserForm1.Controls If c.GroupName = "Season" And c.Value = True Then x = Right(c.Name, Len(c.Name) - 12) End If Next c Hth, Merjet I spoke too soon....I want to check each by GroupName and Value, but c.GroupName is not valid. Only OptionButtons have GroupNames, controls do not. So I tried: Dim o As OptionButton DrngPied.Show 'DrngPied is the form For Each o In DrngPied.Controls If o.GroupName = "SizeOptions" And o.Value = -1 Then sSize = c.Name End If Next o but I get a Type Mismatch at the For Each line. John -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Option Buttons, Forms Control, Excel 2007 - 3 options | Excel Worksheet Functions | |||
Option Buttons from the Forms Toolbar - Excel 2003 | Excel Worksheet Functions | |||
Forms Option Buttons(Can be right mouse selected when sheet is loc | Excel Discussion (Misc queries) | |||
Option Buttons on User Forms | Excel Programming | |||
Forms: Group Boxes and Option Buttons | Excel Programming |