How can I write a VBA code picking 2 option buttons!?? HELP please!

alfa_eng

New Member
Joined
Apr 17, 2015
Messages
31
Hello.

I've got an userform that got two questions:
1) ... yes or no
2) option a or b or c

i've got 6 possible combinations on 6 labels: yes + a or yes + b or yes+c...etc...

and I want if I pick option button yes and option button a that appears the label that got: yes + a, and the other be invisible.
I know how to put label visible and invisible, but I dont know how to combine that code when I've got to pick two option buttons.

Anyone can help me?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
normally, if you have option buttons, you put them in a 'frame'.
you assign the option clicked to the frame.tag for storage.
So in the Yes/No frame, fraYN, you store the value if the user picked Yes by setting fraYN.tag = -1 (yes) ,0 for false.
Then just look at the frame.tag to make things visible or not.

Code:
Private Sub optA_Click()
fraABC.Tag = "A"
EnableBtns
End Sub


Private Sub optB_Click()
fraABC.Tag = "B"
EnableBtns
End Sub


Private Sub optC_Click()
fraABC.Tag = "C"
EnableBtns
End Sub


Private Sub optNo_Click()
fraYN.Tag = 0
EnableBtns
End Sub

Private Sub optYes_Click()
fraYN.Tag = -1
EnableBtns
End Sub

Public Sub EnableBtns()
If fraYN.Tag Then
   btn.Enabled = True
Else
   btn.Enabled = False
End If
End Sub
 
Upvote 0
@ranman256 i appreciate your help but I tried the code and it doesn't work, I dont know If it is because I'm not very good at working whit VBA or if I didn't explain me...

i've got this:
frame_A that got 2 others frames:
frame_a
a) does the element got steel? yes or no (2 option button)

frame_b
b) what kind of steel? type a or type b or type c (3 option button)

and the combinations are in the frame _A in 6 diferent labels
Y+Type a Y+Type B Y+ Type C
N+Type a N+Type B N+TypeC

I wrote that when i click on yes, labels with Y+Type a Y+Type B Y+ Type C are visible and the other are invisible
And after I wrote if I pick type a labels with Y+Type a and N+Type a are visible and the other invisible

I need to pick Yes and type A and only appears Y+ Type A


I didn't understand if the code you gave me can do this!

I'm sorry for disturbing but I really need this and I dont know how to solve! :/
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

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