Private Sub CommandButton1_Click()

G

Guest

How should the code be to use:

Private Sub CommandButton1_Click()

To run this:


Sub Hide_Print_Unhide()
Dim rw As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")
For rw = 1 To 30
If .Cells(rw, "A").Value = "" Then _
.Rows(rw).Hidden = True
Next rw
.PrintOut ' for testing use .PrintPreview
.Range("A1:A30").EntireRow.Hidden = False
End With
Application.ScreenUpdating = True
End Sub


Thanks
Bob
 
D

Dave Peterson

Is the commandbutton on sheet1?

If yes:

Private Sub CommandButton1_Click()
Dim rw As Long
Application.ScreenUpdating = False
'Me is the object that owns the code
'in this case Sheet1
With Me 'Sheets("Sheet1")
For rw = 1 To 30
If .Cells(rw, "A").Value = "" Then _
.Rows(rw).Hidden = True
Next rw
.PrintOut ' for testing use .PrintPreview
.Range("A1:A30").EntireRow.Hidden = False
End With
Application.ScreenUpdating = True
End Sub

Another option would be to just call that same routine:

Private Sub CommandButton1_Click()
call Hide_Print_Unhide
end sub
 
G

Guest

Thanks Dave, works fine.

Dave Peterson said:
Is the commandbutton on sheet1?

If yes:

Private Sub CommandButton1_Click()
Dim rw As Long
Application.ScreenUpdating = False
'Me is the object that owns the code
'in this case Sheet1
With Me 'Sheets("Sheet1")
For rw = 1 To 30
If .Cells(rw, "A").Value = "" Then _
.Rows(rw).Hidden = True
Next rw
.PrintOut ' for testing use .PrintPreview
.Range("A1:A30").EntireRow.Hidden = False
End With
Application.ScreenUpdating = True
End Sub

Another option would be to just call that same routine:

Private Sub CommandButton1_Click()
call Hide_Print_Unhide
end sub
 

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