expand/collapse row button

G

Guest

can I place a button any where in the worksheet to collapse/expand rows? I
would like to place a button +/- on column D to expand/collapse row 2 to 5
(instead of using the grouping tool where you find the button at the left
most corner). Thank you for any assistance.

A B C D
row 1
row 2
row 3
row 4
row 5
 
R

Richard

No need for a button

You could put the following code in the Worksheet_Selection Change
event. It will hide rows 2 to 5 whenever a cell in column D is
selected. Similarly it will unhide the rows if column E is selected

If you really want a button, simply use the same code in an attached
macro.

HTH

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, [D:D]) Is Nothing Then
[2:5].Rows.Hidden = True
End If

If Not Intersect(Target, [E:E]) Is Nothing Then
[2:5].Rows.Hidden = False
End If

End Sub
 
G

Guest

Have a look at Filter

You could put (say) and X in column D in the rows that you want hidden and
use Custom Filter on Columnd D (or on D1:D5) to display only cells that don't
contain X

Data > Filter > AutoFilter

HTH

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top