Hide and Show rows button

DSLA

Active Member
Joined
Jun 6, 2005
Messages
301
Hi, i have 2 button for hiding and showing certain rows, but i would like to make it possible to hide/show rows with only one button.

When i click once it shows the cells, when i click again it hides the rows.

Here are the codes:
Private Sub CommandButton1_Click()
Rows("28:36").Select
Selection.EntireRow.Hidden = False
End Sub

Private Sub CommandButton3_Click()
Rows("28:36").Select
Selection.EntireRow.Hidden = True
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi DSLA,

You can toggle the Hidden property of the rows by using the code:

Selection.EntireRow.Hidden = NOT Selection.EntireRow.Hidden

This simply reverses the current TRUE/FALSE value.

Keep Excelling.

Damon
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
55,853
Office Version
  1. 365
Platform
  1. Windows
DSLA

Also, generally you do not have to actually SELECT rows/ranges/cells to work on them and it is generally quicker not to do so. In this case, I think that you could use this:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()
    Rows("28:36").EntireRow.Hidden = <SPAN style="color:#00007F">Not</SPAN> Rows("28:36").EntireRow.Hidden
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,722
Hi DSLA,

have you thought about Grouping and Outlining to hide and unhide specific rows easily?

Just a thought.
 

Forum statistics

Threads
1,172,016
Messages
5,878,752
Members
433,369
Latest member
Applewood

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
Top