I have a VBA that does print the desired print area; however, I need the VBA code to hide blank cells during print preview
Private Sub cmd_PrintPreview_Click()
Me.Hide
Dim curPrinter As String
curPrinter = Application.ActivePrinter
ActiveWindow.ActiveSheet.PrintPreview
Application.ActivePrinter = curPrinter
Me.Show
End Sub
I do have a Macro: That will hide empty cells in a range but can't figure out how to insert (Call Print_NonBlank_Rows) as a print preview
Sub Print_NonBlank_Rows()
Dim rng As Range, cell As Range, toHide As Range
Dim r&, c%, b%, n%
Set rng = ActiveSheet.UsedRange
For r = 1 To rng.Rows.Count
b = 0
For c = 1 To rng.Columns.Count
If rng.Cells(r, c).Value = 0 Then
b = b + 1
End If
Next c
If b = rng.Columns.Count Then
If n = 0 Then
Set toHide = rng.Cells(r, c).EntireRow
n = 1
Else
Set toHide = Union(toHide, rng.Cells(r, c).EntireRow)
End If
End If
Next r
toHide.EntireRow.Hidden = True
ActiveSheet.PrintOut Copies:=1
toHide.EntireRow.Hidden = False
End Sub
Any help or suggestions, please!
Bookmarks