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

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.
Hi! Could you tell me code if I have 2 more rows 32:40 and 41:49 where should I put in code above?
 
Upvote 0
Depends on what you want to do.
 
Upvote 0
You send me formula for hide/unhide rows
14:22
23:31
Now I want 2 more extra
32:40
41:39
When I click the button “-“ hide 14:22
When I click second time hide 23:31
When I click third time hide 32:40
Or vice versa when I click button “+”
 
Upvote 0
That is now a sufficiently different question, so you will need to start a new thread. Thanks
 
Upvote 0
I'm a little confused. The only difference is that it would add new rows to the existing formula.
 
Upvote 0
Yes but it needs totally different code as you know want to click multiple times with a different action each time, rather than a simple toggle.
 
Upvote 0
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
Please start a new thread for this question. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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