Toggle button Macro

gobblechops

New Member
Joined
Apr 27, 2017
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hi,

Below is some VBA code used with a toggle button to hide/unhide rows 8:10. This works perfectly.

I need to amend the code so the button hides/unhides rows 16,22,23,26,30,32,46,49,52,55,58 AND Columns G,H,I,J.

Private Sub ToggleButton1_Click()
Dim xAddress As String
xAddress = "8:10"
If ToggleButton1.Value Then
Application.ActiveSheet.Rows(xAddress).Hidden = True
ToggleButton1.Caption = "Show Scenario"
Else
Application.ActiveSheet.Rows(xAddress).Hidden = False
ToggleButton1.Caption = "Hide Scenario"
End If
End Sub

Thanks in advance.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi,
untested

Code:
Private Sub ToggleButton1_Click()
    Range("G:J").EntireColumn.Hidden = ToggleButton1.Value
    Range("8:10,16:16,22:23,26:26,30:30,32:32,46:46,49:49,52:52,55:55,58:58").EntireRow.Hidden = ToggleButton1.Value
    ToggleButton1.Caption = IIf(ToggleButton1.Value, "Show Scenario", "Hide Scenario")
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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