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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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.
 
Upvote 0
Yes, you can code it, but to help I need to know if the Frame is a Worksheet control or a UserForm?
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,915
Members
448,532
Latest member
9Kimo3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top