Hide and Unhide Rows button

F

FinlandGuy

I have this code for a button to hide and Unhide rows (7 to 10) But it
hides everything in my sheet. I just want it to hide just the 4 rows.

Private Sub CommandButton8_Click()
If CommandButton8.Caption = "Hide" Then
Range("7:7,8:8,9:9,10:10").Select
Selection.EntireRow.Hidden = True
CommandButton8.Caption = "UnHide"
Else
Range("7:7,8:8,9:9,10:10").Select
Selection.EntireRow.Hidden = False
CommandButton8.Caption = "Hide"
End If
End Sub

Thanks in advance,

Cheers John
 
S

Sam Wilson

Try this:

Private Sub CommandButton8_Click()
If CommandButton8.Caption = "Hide" Then
Rows("7:10").hidden=true
CommandButton8.Caption = "UnHide"
Else
Rows("7:10").hidden=false
CommandButton8.Caption = "Hide"
End If
End Sub
 
S

Stefi

Try this:
Private Sub CommandButton8_Click()
If CommandButton8.Caption = "Hide" Then
Range("7:10").EntireRow.Hidden = True
CommandButton8.Caption = "UnHide"
Else
Range("7:10").EntireRow.Hidden = False
CommandButton8.Caption = "Hide"
End If
End Sub

Regards,
Stefi


„FinlandGuy†ezt írta:
 
L

Les Stout

Hi John, it works fine for me. you can shorten your code with excel 2003

Private Sub CommandButton8_Click()
If CommandButton8.Caption = "Hide" Then
Range("7:10").EntireRow.Hidden = True
CommandButton8.Caption = "UnHide"
Else
Range("7:10").EntireRow.Hidden = False
CommandButton8.Caption = "Hide"
End If
End Sub


Best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
 

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