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 does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,785
Messages
6,121,543
Members
449,038
Latest member
Guest1337

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