VBA code for hide/unhide separate rows

mare23

New Member
Joined
Oct 28, 2020
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi everyone!

Is there any VBA code for hide/unhide separate rows. for example
When I click - button once hide all rows from 23-31 and when I click the - button a second time hide rows 14-22
When I click + button once unhide all rows from 14 -22 and when I click the + button a second time hide rows 23-31


Thx
Mare
 

Attachments

  • example.jpg
    example.jpg
    39.1 KB · Views: 17
Great, thx!
Code:
Option Explicit

Private bToggleMINUS As Boolean
Private bTogglePLUS  As Boolean

Public Sub Btn_MINUS()
    If Not bToggleMINUS Then
        Me.Rows("26:53").Hidden = True
        Me.Rows("82:107").Hidden = True
        Me.Rows("137:161").Hidden = True
        Me.Rows("191:215").Hidden = True
        Me.Rows("244:269").Hidden = True
        Me.Rows("299:323").Hidden = True
    End If
    bToggleMINUS = Not bToggleMINUS
End Sub

Public Sub Btn_PLUS()
    If Not bTogglePLUS Then
        Me.Rows("26:53").Hidden = False
        Me.Rows("82:107").Hidden = False
        Me.Rows("137:161").Hidden = False
        Me.Rows("191:215").Hidden = False
        Me.Rows("244:269").Hidden = False
        Me.Rows("299:323").Hidden = False
    End If
    bTogglePLUS = Not bTogglePLUS
End Sub

I am using the above code to hide a group of rows, but I have to hit each button twice for it to hide and unhide everything. Is there a way to make it happen with just one click?
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,216,101
Messages
6,128,840
Members
449,471
Latest member
lachbee

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