Hiding/Unhiding Sheet in a Workbook Using a Radio Button

lakshya167

New Member
Joined
Jun 26, 2014
Messages
5
Hi!

The Problem
So I'm making a form in Excel. I have two options buttons labelled "Yes" & "No". These two options buttons are in Sheet 1.

I want to make sheet 2 visible if any user selects "Yes" and hidden if a user selects "No".

I'm using Excel for Mac 2011 so there are no ActiveX controls.

What I've Done So Far
Insert two option buttons, named OptionButton1 (caption"Yes") and OptionButton2 (caption"No").

Clicked on Editor ->Double Clicked on Sheet1 (current sheet containing the 2 option buttons).
Typed in the following code:
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
Sheets("Sheet2").Visible = xlSheetVisible
Else
Sheets("Sheet2").Visible = xlSheetHidden
End If
End Sub




Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
Sheets("Sheet2").Visible = xlSheetHidden
Else
Sheets("Sheet2").Visible = xlSheetVisible
End If
End Sub

Clicked save.

Right clicked OptionButton1 -> Assign Macro -> OptionButton1_Click
Right clicked OptionButton2 -> Assign Macro -> OptionButton2_Click

The Error
When I click on the option button "Yes" or "No" the sheet 2 doesn't hide.
I get the error message: The macro 'Workbook1.xlsm!OptionButton1_Click' cannot be found.
Simmilar for Option Button 2.

Also, during the editor, when I click on the run button (play) I get the following error:
Runtime Error '424'
Object Required



Don't know what to do. I'm new to coding at excel, so please don't judge.

Thanks for the help! Much appreciated!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try something like this....

Code:
Sub OptionButton1_Click()

Set shp1 = Worksheets("Sheet1").Shapes("Option Button 1")
      
If shp1.ControlFormat.Value = xlOn Then
Sheets("Sheet2").Visible = xlSheetHidden
End If
End Sub
 
Upvote 0
Try something like this....

Code:
Sub OptionButton1_Click()

Set shp1 = Worksheets("Sheet1").Shapes("Option Button 1")
      
If shp1.ControlFormat.Value = xlOn Then
Sheets("Sheet2").Visible = xlSheetHidden
End If
End Sub

Now it giving me "Out Of Memory" error whenever I click on Option Button 1
 
Upvote 0
Code:
Sub OptionButton1_Click()

Set shp1 = Worksheets("Sheet1").Shapes("Option Button 1")
      
If shp1.ControlFormat.Value = xlOn Then
Sheets("Sheet2").Visible = xlSheetHidden
Else
Sheets("Sheet2").Visible = xlSheetVisible

End If
End Sub

Maybe add the what to do if its not ticked? Like this, sorry im travelling now so I am on my phone.
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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