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.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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: 23
Upvote 0
You could put the option buttons inside a frame (.SpecialEffect = fmSpecialEffectFlat , .Caption="" to make it invisible) and then toggle the visibility of that Frame.
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,405
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