ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   hide and unhide option buttons (https://www.excelbanter.com/excel-programming/398942-hide-unhide-option-buttons.html)

gbpg

hide and unhide option buttons
 
I Have set the visible prporety to false for 2 option buttons on a form. If i
select no for the vsible option button I want one of the two non visible
option buttons to appear. Any ideas?
Note these are not linked to cells

OssieMac

hide and unhide option buttons
 
Hi,

Not sure if I understand your request. How do you select 'No' for an option
button unless you click on another button and you have said the others are
not visible. (Unless of course you are doing so in VBA).

Anyway here is some examples of setting the option buttons to visible or not
visible using VBA. Perhaps it will help but I'm not confident because I do
not really understand your requirement.

ActiveSheet.OptionButton2.Visible = True
ActiveSheet.OptionButton3.Visible = False

Following turns buttons on and off in VBA.
ActiveSheet.OptionButton1 = True
ActiveSheet.OptionButton1 = False

Regards,

OssieMac


"gbpg" wrote:

I Have set the visible prporety to false for 2 option buttons on a form. If i
select no for the vsible option button I want one of the two non visible
option buttons to appear. Any ideas?
Note these are not linked to cells


gbpg

hide and unhide option buttons
 
Hi:
The first set of yes and no buttons are visible.
If I select no I want the second set of buttons of yes no to appear and the
label (which is a question) to appear. I made the second and third set not
visible not with vba but in the properties section i.e. visible is false.


"OssieMac" wrote:

Hi,

Not sure if I understand your request. How do you select 'No' for an option
button unless you click on another button and you have said the others are
not visible. (Unless of course you are doing so in VBA).

Anyway here is some examples of setting the option buttons to visible or not
visible using VBA. Perhaps it will help but I'm not confident because I do
not really understand your requirement.

ActiveSheet.OptionButton2.Visible = True
ActiveSheet.OptionButton3.Visible = False

Following turns buttons on and off in VBA.
ActiveSheet.OptionButton1 = True
ActiveSheet.OptionButton1 = False

Regards,

OssieMac


"gbpg" wrote:

I Have set the visible prporety to false for 2 option buttons on a form. If i
select no for the vsible option button I want one of the two non visible
option buttons to appear. Any ideas?
Note these are not linked to cells


OssieMac

hide and unhide option buttons
 
I think that I understand now. The option buttons are in different groups.
Not sure if you need instructions to put the code into the VBA editor but I
will include it anyway.

If your option button names do not match the ones in the code then you will
have to edit the code and correct names.

On the worksheet where the option buttons exist, click on the Design Mode
button.
Right click on the first 'Yes' option button.
Select View Code.
Copy the following code and paste it in between the Private Sub and End Sub
which automatically appeared.

ActiveSheet.OptionButton3.Visible = False
ActiveSheet.OptionButton4.Visible = False

Alt/F11 will take you back to the worksheet.

Right click on your first 'No' button.(While still in Design Mode)
Select View Code.
Copy the following code and paste it in between the Private Sub and End Sub
which automatically appeared.

ActiveSheet.OptionButton3.Visible = True
ActiveSheet.OptionButton4.Visible = True

Close the VBA Editor (The cross in the red rectangle at the top right)

Alt/F11 to return to the worksheet.
Turn off Design Mode.

Now the code is supposed to make buttons 3 and 4 non visible when the first
Yes button is clicked and make them visible if the first No button is
clicked. However, it is dependent on the second set of buttons having
matching names to the ones in the macro. That is OptionButton3 and
OptionButton4. If not then you will need to edit the code to match.

To return to the VBA editor Alt/F11 toggles between the editor and the
worksheet. If the code you pasted in is not immediately visible, then in the
Project Explorer on the left, double click on the sheet name matching the one
with the buttons.

Just as an added extra, the following code can be used to set the caption on
the buttons:-

ActiveSheet.OptionButton3.Caption = "My Question one"
ActiveSheet.OptionButton4.Caption = "My Question two"

Alternative method to set the caption equal to cell values

ActiveSheet.OptionButton3.Caption = ActiveSheet.Range("A1")
ActiveSheet.OptionButton4.Caption = ActiveSheet.Range("B1")


Regards,

OssieMac



OssieMac

hide and unhide option buttons
 
I have realized that you could run into problems making your option buttons
visible so that you can get into properties to check their names so here is a
method of doing so if required:-

Ensure that the worksheet with the option buttons is your selected one.
Alt/F11 to open VBA editor.
Click on menu item Insert then Module.
Copy the macro below and paste it into the module.
Click anywhere within the code (so the cursor is within the code)
Press F5 to run the code.
Alt/F11 to return to the worksheet.
All buttons should be visible.

To get back to the code if required during your development:-
Alt/F11 and then expand modules and double click Module1.


Sub Identify_Controls()
For Each shp In ActiveSheet.Shapes
shp.Visible = True
Next
End Sub



Regards,

OssieMac



All times are GMT +1. The time now is 01:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com