optionbutton to create more options

joacro

Board Regular
Joined
Jun 24, 2010
Messages
158
Hi there,
I hope someone will be able to help me.

I have a user form. On the userform I have various options.
Group 1
option for family(optfam) and option for principal(optprin)
Group 2
option for core/saver(optcore) and option for executive(optexe)

What I will need is:
If optfam and optcore = true then
7 other options need to appear. eg
opt1 caption R0 - R1000
opt 2 caption R1001 - R2000 etc

The same needs to happen when should I select
optfam and optexe = true
7 other options need to appear eg,
optcf caption R7000 - R8000

Hope someone can help with this. Everything needs to change on the userform

Thanks in advance
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
The title of your post is a bit deceptive. Creating new options on the fly will probably be a lot more work than just creating all of the options at design time and displaying the appropriate ones when needed. If your option buttons are in frames you can hide or show the frame and the option buttons in the frame will follow.

Code:
UserForm1.Frame1.Visible = False
UserForm1.Frame1.Visible = True

UserForm1.OptionButton1.Visible = True
UserForm1.OptionButton1.Visible = False

You can also control the position and size of the controls in code if you need to adjust the appearance of your form.

Gary
 
Upvote 0
Hi there thank you for your quick reply.

I tried you suggestion but can't seem to get it to work

This is what I did
Private Sub oftfam_Click()
If optfam = True Then
If optcore = True Then
UserForm1.Frmhpc2.Visible = False
UserForm1.frmHPC1.Visible = True
End If
End Sub

Hope someone can help me with this

Regards
 
Upvote 0
The sample you supplied is missing an "End If". Even if you include the missing "End If" it would not work as I think you intend. The second If statement, "If optcore ...", would only be evaluated when the first If statement is true. Otherwise, it would never reach the "If optcore = True Then" statement.

Below is a sample of what I think you are looking for.

Gary

Code:
Private Sub oftfam_Click()
 
'Next line of code may have to be something like the following
'depending on where the code and controls are located.
 
'If UserForm1.optfam = True And UserForm1.optcore = True Then
 
If optfam = True And optcore = True Then
    UserForm1.Frmhpc2.Visible = False
    UserForm1.frmHPC1.Visible = True
End If
 
End Sub
 
Upvote 0
Hi there Gary,

Thank you for your reply.
I tried your suggestion above, but with no luck.
Am i doing something wrong.

Both frames are still visible even if I select optcore and optfam

Any suggestions
 
Upvote 0
I have sent you a private message containing my email address. If you care to send me a copy of your workbook, I'll see what I can do.

With forms and controls involved this is difficult to troubleshoot without being able to see everything and how it is set up.

I have XL 2007 available. If your version is higher than that I may not be able to help unless you can save back to 2007 or previous.

Gary
 
Upvote 0
HI there Gary,

Thanks a lot for giving me the solution. I found my problem. I needed to paste the code in both optfam and optcore.

Once again thank you, you are always the first to help on a lot of my problems!!!
 
Upvote 0
Hi Gary,

Now I encounter a problem.

I did the same with two other option, now it doesn't seem to work.

Can I send the workbook trough e-mail so that you can have a look at it?
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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