| 
    
     |  | UserFormに、OptionButtonで選択するグループが複数有る場合なんか こんな事をすると楽かも?
 
 例えば、UserFormに、Frame1が有り、その中にOptionButton1〜OptionButton3
 Frame2が有り、その中にOptionButton4〜OptionButton6が有るとします
 
 UserFormのコードモジュルールに記述
 
 Option Explicit
 
 'Groupの値取得クラスの配列
 Private clsGroup() As Class1
 
 Private Sub UserForm_Initialize()
 
 Dim i As Long
 Dim j As Long
 
 'ClassにOptionButtonを設定
 For i = 0 To Controls.Count - 1
 If TypeName(Controls(i)) _
 = "OptionButton" Then
 j = j + 1
 ReDim Preserve clsGroup(1 To j)
 Set clsGroup(j) = New Class1
 clsGroup(j).Button = Controls(i)
 End If
 Next i
 
 End Sub
 
 Private Sub UserForm_Terminate()
 
 Dim i As Long
 
 'Classを破棄
 For i = 1 To UBound(clsGroup)
 Set clsGroup(i) = Nothing
 Next i
 
 End Sub
 
 Private Sub CommandButton1_Click()
 
 With Frame1
 If .Tag<>"" then
 MsgBox .Caption & "Groupの" & .Tag & "が選択されています"
 Else
 MsgBox .Caption & "GroupのOptionが選択されていません"
 End if
 End With
 
 With Frame2
 If .Tag<>"" then
 MsgBox .Caption & "Groupの" & .Tag & "が選択されています"
 Else
 MsgBox .Caption & "GroupのOptionが選択されていません"
 End if
 End With
 
 End Sub
 
 VBEの「挿入」→「Classモジュール」でClassモジュールを追加し
 Classモジュールの名前を「Class1」とし以下を記述
 
 Option Explicit
 
 Private WithEvents optButton As MSForms.OptionButton
 
 Public Property Let Button(ByVal optNewValue As MSForms.OptionButton)
 
 Set optButton = optNewValue
 
 End Property
 
 Private Sub Class_Terminate()
 
 Set optButton = Nothing
 
 End Sub
 
 Private Sub optButton_Click()
 
 'OptionButtonがClickされた場合、
 'OptionButtonのCaptionをフレームのTagに代入
 With optButton
 .Parent.Tag = .Caption
 End With
 
 End Sub
 
 
 上記のコードでは、OptionButtonが選択されると、
 選択されたOptionButtonの有るFrameのTagに、選択されたOptionButtonのCaptionが代入されますので、
 FrameのTagを調べ、Tagが""の場合OptionButtonが選択がされていず、
 Tagが""でないなら、OptionButtonが選択がされている事に成ります
 
 |  |