Hide and Show rows button

DSLA

Active Member
Joined
Jun 6, 2005
Messages
296
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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

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
49,439
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,547
Hi DSLA,

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

Just a thought.
 

Forum statistics

Threads
1,136,584
Messages
5,676,659
Members
419,638
Latest member
GlenMc52

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