Option Explicit
Sub PrintVisibleRows(sht As Worksheet)
Dim ar() 'will hold hidden rows
Dim intVisibleAreas, intArea As Integer
Dim objActiveSheet As Worksheet
Dim objVisibleCells As Range
'\first get the # of visible rows areas
intVisibleAreas = sht.Cells.SpecialCells(xlCellTypeVisible).Areas.Count
'\if visible areas >1 it means there are some hidden rows in the worksheet
If intVisibleAreas > 1 Then
'\remember the current sheet for subsequent retrieval
Set objActiveSheet = ActiveSheet
'\lots of flickering ahead so we'd better turn off application settings
With Application
.DisplayAlerts = False
.ScreenUpdating = False
'\now ,let's make a temporary copy of our sheet so we can mess with it
'\...we don't want to delete any rows in the original sheet !
sht.Copy After:=Sheets(Sheets.Count)
Set objVisibleCells = ActiveSheet.Cells.SpecialCells(xlCellTypeVisible)
'\place all the hidden rows in our array and delete them
'\so as to ensure no blank pages are printed
With objVisibleCells
ReDim ar(.Areas.Count - 1, 2)
On Error Resume Next
For intArea = 1 To .Areas.Count - 1
ar(intArea, 1) = .Areas(intArea).Row + .Areas(intArea). _
Rows.Count: ar(intArea, 2) = .Areas(intArea + 1).Row - 1
.Rows(ar(intArea, 1) & ":" & ar(intArea, 2)).Delete
Next intArea
'\print the sheet minus blank pages
ActiveSheet.PrintOut
'\we don't need the copy anymore so just delete it
ActiveSheet.Delete
End With
'\restore normal XL settings
.DisplayAlerts = True
.ScreenUpdating = True
End With
'\go back where we were before requesting the printing -it's only polite :)
objActiveSheet.Activate
End If
End Sub
'____________________________________________________________________________________
Sub Test()
PrintVisibleRows Sheet3 '\replace this parameter with any sheet as required
End Sub