Command buttons linked to moving rows

S

steal_92

I have a worksheet where I need to quickly display hidden rows (so as to
‘drill-down’ to more detailed information) and then re-hide the rows when
necessary.

I have set up command buttons linked to the following macros to do this:
_____

Private Sub CommandButton11_Click()

Rows("88:88").Select
Selection.EntireRow.Hidden = False
Range("A88").Select
End Sub

Private Sub CommandButton12_Click()

Rows("88").Select
Selection.EntireRow.Hidden = True
End Sub
_____

This works perfectly well until I insert or delete rows above the command
buttons. When I do that, the buttons now hide the wrong rows.

Is it possible to lock the macro so that it will only affect the desired
rows, wherever they are in the worksheet?
 
J

Jim Cone

Name a cell in the row and use that name in your code.
Also, you do not need two buttons or two sets of code...

Range("TheCell").EntireRow.Hidden = Not Range("TheCell").EntireRow.Hidden
--
Jim Cone
Portland, Oregon USA




"steal_92" <[email protected]>
wrote in message
I have a worksheet where I need to quickly display hidden rows (so as to
‘drill-down’ to more detailed information) and then re-hide the rows when
necessary.
I have set up command buttons linked to the following macros to do this:
_____

Private Sub CommandButton11_Click()
Rows("88:88").Select
Selection.EntireRow.Hidden = False
Range("A88").Select
End Sub

Private Sub CommandButton12_Click()
Rows("88").Select
Selection.EntireRow.Hidden = True
End Sub
_____

This works perfectly well until I insert or delete rows above the command
buttons. When I do that, the buttons now hide the wrong rows.
Is it possible to lock the macro so that it will only affect the desired
rows, wherever they are in the worksheet?
 

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