Hide/unhide non consecutive rows with toggle button

onthegreen03

Board Regular
Joined
Jun 30, 2016
Messages
168
Office Version
  1. 365
Platform
  1. Windows
Hi. I have the code below which I'm hoping will hide the non consecutive rows listed, but when I run the code it errors out. The code was working when it was just 2 consecutive rows (1:2), but now that I need to hide/unhide multiple rows (non consecutive) it no longer works. Any help would be appreciated.

Private Sub ToggleButton1_Click()

Dim xAddress As String

xAddress = "19,30,43,49,55,86,93,103,109,115" 'change this to the row numbers



If ToggleButton1.Value Then

Application.ActiveSheet.Rows(xAddress).Hidden = True

ToggleButton1.Caption = "Show Row"

Else

Application.ActiveSheet.Rows(xAddress).Hidden = False

ToggleButton1.Caption = "Hide Row"

End If

End Sub
 

Attachments

  • 1695304243366.png
    1695304243366.png
    22.4 KB · Views: 13

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Maybe this:
VBA Code:
Private Sub ToggleButton1_Click()

Dim xAddress As String

xAddress = "A19,A30,A43,A49,A55,A86,A93,A103,A109,A115"

If ToggleButton1.Value Then

    Range(xAddress).EntireRow.Hidden = True
   
    ToggleButton1.Caption = "Show Row"

Else

    Range(xAddress).EntireRow.Hidden = False
   
    ToggleButton1.Caption = "Hide Row"

End If

End Sub
 
Upvote 0
Solution
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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