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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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
 
Upvote 0
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>
 
Upvote 0
Hi DSLA,

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

Just a thought.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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