The
GroupName property exists to separate optionbutton groups, but it must be in the same container (form, frame, page).
If they are in different containers, it can be a frame or a page, they will be in different groups even though they have the same group name.
Check the following:
Office VBA reference topic
learn.microsoft.com
1)
Then you can choose to put all the option buttons in the same container with the same groupname.
2)
Or with the following code:
Create a class module:
Class1 and put the following code:
VBA Code:
Public WithEvents MultipleOptionButton As MSForms.OptionButton '<--- At the beginning of all the code
Private Sub MultipleOptionButton_Click()
Dim ctrl As MSForms.Control
Dim s As String
s = MultipleOptionButton.Caption
For Each ctrl In UserForm1.Controls 'Fit to the name of your userform
If TypeName(ctrl) = "OptionButton" Then
If ctrl.Caption <> s Then
ctrl.Value = False
End If
End If
Next
End Sub
In your Userform:
VBA Code:
Option Explicit '<--- At the beginning of all the code
Dim OptBt() As New Class1 '<--- At the beginning of all the code
Private Sub UserForm_Initialize()
Dim i As Long, ctrl As MSForms.Control
i = 1
For Each ctrl In Me.Controls
If TypeName(ctrl) = "OptionButton" Then
If ctrl.Caption Like "CH -*" Then
ReDim Preserve OptBt(i)
Set OptBt(i).MultipleOptionButton = ctrl
i = i + 1
End If
End If
Next
End Sub
Note: The above code will work for all optionbuttons that start with the characters in the caption: "CH -"
----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --