radio buttons on forms

Lino

Active Member
Joined
Feb 27, 2002
Messages
429
Hello,

I have 7 radio buttons on a form however three are in one frame and 4 are in another frame and that causes each set of radio buttons to operate independently of each other.

Is there a way (without putting them in the same frame) to get it to work so if any radio button is selected that any of the remaining six would be unselected.

is that clear?

thanks,

Lino
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
OptionButtons with the same GroupName are mutually exclusive, but this property is ignored if they are in a Frame.

If your Frames are just for appearance you could use Label controls (with a border) instead.
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
Yes, you can code it, but to help I need to know if the Frame is a Worksheet control or a UserForm?
 

Lino

Active Member
Joined
Feb 27, 2002
Messages
429
it is a userform

how do u use a label control...where is it...i don't see it in the toolbox...but perhaps it is there as this is news to me

thanks,

Lino
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539

ADVERTISEMENT

O.K.

I built an UserForm with two Frames on it, Frame1 has three Radio Option Buttons and Frame2 has four in it.

The code below will reset all of these buttons except for the one currently clicked. To actually do something with the Click event you will need to trap the Click-Event for that Button or Public Define Variables to test with. To use the click events below to do this add your new code below my code. I would test for which button is clicked with the "Select Case" structure attached to a Command Button Click Event, to delay the responce, for instant responce use the Radio Option Button Click Events!

This way you bypass the Frames all together!


Private Sub OptionButton1_Click()
If OptionButton1 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton4 = False: OptionButton5 = False: OptionButton6 = False: OptionButton7 = False
End Sub

Private Sub OptionButton2_Click()
If OptionButton2 = True Then: _
OptionButton1 = False: OptionButton3 = False: OptionButton4 = False: OptionButton5 = False: OptionButton6 = False: OptionButton7 = False
End Sub

Private Sub OptionButton3_Click()
If OptionButton3 = True Then: _
OptionButton2 = False: OptionButton1 = False: OptionButton4 = False: OptionButton5 = False: OptionButton6 = False: OptionButton7 = False
End Sub

Private Sub OptionButton4_Click()
If OptionButton4 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton1 = False: OptionButton5 = False: OptionButton6 = False: OptionButton7 = False
End Sub

Private Sub OptionButton5_Click()
If OptionButton5 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton4 = False: OptionButton1 = False: OptionButton6 = False: OptionButton7 = False
End Sub

Private Sub OptionButton6_Click()
If OptionButton6 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton4 = False: OptionButton5 = False: OptionButton1 = False: OptionButton7 = False
End Sub

Private Sub OptionButton7_Click()
If OptionButton7 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton4 = False: OptionButton5 = False: OptionButton1 = False: OptionButton1 = False
End Sub
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
You can also trap which OptionButton was selected if any, as well as reset, using the FormButton "CommandButton1_Click" code below:


Public myB%

Private Sub OptionButton1_Click()
If OptionButton1 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton4 = False: _
OptionButton5 = False: OptionButton6 = False: OptionButton7 = False: myB = 1
End Sub

Private Sub OptionButton2_Click()
If OptionButton2 = True Then: _
OptionButton1 = False: OptionButton3 = False: OptionButton4 = False: _
OptionButton5 = False: OptionButton6 = False: OptionButton7 = False: myB = 2
End Sub

Private Sub OptionButton3_Click()
If OptionButton3 = True Then: _
OptionButton2 = False: OptionButton1 = False: OptionButton4 = False: _
OptionButton5 = False: OptionButton6 = False: OptionButton7 = False: myB = 3
End Sub

Private Sub OptionButton4_Click()
If OptionButton4 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton1 = False: _
OptionButton5 = False: OptionButton6 = False: OptionButton7 = False: myB = 4
End Sub

Private Sub OptionButton5_Click()
If OptionButton5 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton4 = False: _
OptionButton1 = False: OptionButton6 = False: OptionButton7 = False: myB = 5
End Sub

Private Sub OptionButton6_Click()
If OptionButton6 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton4 = False: _
OptionButton5 = False: OptionButton1 = False: OptionButton7 = False: myB = 6
End Sub

Private Sub OptionButton7_Click()
If OptionButton7 = True Then: _
OptionButton2 = False: OptionButton3 = False: OptionButton4 = False: _
OptionButton5 = False: OptionButton1 = False: OptionButton1 = False: myB = 7
End Sub


Private Sub CommandButton1_Click()
Dim i%, myROBut As Control, myBNm$

For Each myROBut In Controls
For i = 1 To 7

myBNm = "OptionButton" & i

If myB = 0 Then GoTo myEnd

If i = myB Then GoTo myFound

Next i
Next myROBut

myFound:
MsgBox "You selected: " & myBNm

myEnd:
If myB = 0 Then MsgBox "You did not select an option!"
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,009
Messages
5,569,596
Members
412,281
Latest member
GraYmOnD0808
Top