Wingersiow
New Member
- Joined
- Aug 2, 2014
- Messages
- 14
Hi,
As a complete newbie I really seem to be struggling with this problem and am hoping that someone has a nice easy answer.
I have a sheet which is essentially being used as a questionnaire. On the sheet are a number of group boxes which each contain up to a maximum of 8 option buttons (all form control) I need to ensure that each group box has an option button selected before it is submitted. I would therefore like to loop through each group box in turn to check that one of the option buttons has been selected before moving on to the next Group Box. However I only seem to be able to loop through each option button on the sheet. The MsgBoxes are there just to help me with some basic testing. Any ideas would be really appreciated. My code is:
Sub Button63_Click()
Dim OB As OptionButton
Dim Group As GroupBox
For Each Group In ActiveSheet.GroupBoxes
For Each OB In ActiveSheet.OptionButtons 'I guess that the problem is here as I need
'to look at each option button in the Group rather that the sheet
MsgBox "MSG 1 Group " & Group.Name & " OB Name " & OB.Name
If OB.Value = 1 Then
OB.Select
With Selection.Interior
.Pattern = xlSolid
.Color = 255
End With
MsgBox "Msg 2 " & Group.Name & " " & OB.Name & _
vbNewLine & _
"Alt text: " & OB.ShapeRange.AlternativeText
End If
Next
Next
End Sub
Thanks
Wingersiow
As a complete newbie I really seem to be struggling with this problem and am hoping that someone has a nice easy answer.
I have a sheet which is essentially being used as a questionnaire. On the sheet are a number of group boxes which each contain up to a maximum of 8 option buttons (all form control) I need to ensure that each group box has an option button selected before it is submitted. I would therefore like to loop through each group box in turn to check that one of the option buttons has been selected before moving on to the next Group Box. However I only seem to be able to loop through each option button on the sheet. The MsgBoxes are there just to help me with some basic testing. Any ideas would be really appreciated. My code is:
Sub Button63_Click()
Dim OB As OptionButton
Dim Group As GroupBox
For Each Group In ActiveSheet.GroupBoxes
For Each OB In ActiveSheet.OptionButtons 'I guess that the problem is here as I need
'to look at each option button in the Group rather that the sheet
MsgBox "MSG 1 Group " & Group.Name & " OB Name " & OB.Name
If OB.Value = 1 Then
OB.Select
With Selection.Interior
.Pattern = xlSolid
.Color = 255
End With
MsgBox "Msg 2 " & Group.Name & " " & OB.Name & _
vbNewLine & _
"Alt text: " & OB.ShapeRange.AlternativeText
End If
Next
Next
End Sub
Thanks
Wingersiow