Hide Multiple Option Buttons

riedyp

Board Regular
Joined
Feb 13, 2020
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am trying to reduce the number of lines of code in my workbook where I am hiding and unhiding a lot of Option Buttons. Is there a way to hide/unhide multiple option buttons in one line?


VBA Code:
    ActiveSheet.Shapes("Option Button 20").Visible = True 'Yes  Sub 1
    ActiveSheet.Shapes("Option Button 21").Visible = True 'No  Sub 1

Thank you.
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,231
Office Version
  1. 365
Platform
  1. Windows
You could loop them like
VBA Code:
Sub riedyp()
   Dim i As Long
   For i = 3 To 9
      ActiveSheet.Shapes("Option Button " & i).Visible = True
   Next i
End Sub
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
if numbers are not sequential
VBA Code:
    Dim n As Variant
    For Each n In Array(3, 4, 25)
        ActiveSheet.Shapes("Option Button " & n).Visible = True
    Next n
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
and to toggle between visible and hidden
VBA Code:
    Dim n As Variant
    For Each n In Array(3, 4, 25)
        With ActiveSheet.Shapes("Option Button " & n)
            .Visible = Not .Visible
        End With
    Next n
 

riedyp

Board Regular
Joined
Feb 13, 2020
Messages
88
Office Version
  1. 365
Platform
  1. Windows
thanks for your inputs. I should clarify that it is a questionnaire where the visibility of one or multiple option buttons is dependent on whether a different option button is selected. See attached photo.
 

Attachments

  • hide.PNG
    hide.PNG
    15.5 KB · Views: 6

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,948
You could put the option buttons inside a frame (.SpecialEffect = fmSpecialEffectFlat , .Caption="" to make it invisible) and then toggle the visibility of that Frame.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,923
Messages
5,621,621
Members
415,848
Latest member
LCC

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
Top