Command Button

F

Freshman

Dear experts,

I want to create a command button and when I click it, rows under row 30
will be collapsed. When I click the button again, it toggles to expand the
rows under row 30. In the meantime, can the wording on the button be changed
to "expand rows" in collapse status and "collapse rows" in expand status? Is
it required a VBA code to operate? If yes, please kindly advise the code.

Thanks in advance
 
C

Corey

Something lik:


Sub HideRows()
With Sheet1
Rows("30:65536").Select
Selection.EntireRow.Hidden = True
ActiveSheet.Shapes("CommandButton1").Select
Sheet1.CommandButton1.Caption = "Expand Rows"
End With
End Sub

Sub ShowRows()
With Sheet1
Rows("30:65536").Select
Selection.EntireRow.unHide = True
ActiveSheet.Shapes("CommandButton1").Select
Sheet1.CommandButton1.Caption = "Colapse Rows"
End With
End Sub



Corey....
 
F

Freshman

Hi Roger,

Your tip works great and thanks once again. Have a nice day. Cheers.
 

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