erutherford
Active Member
- Joined
- Dec 19, 2016
- Messages
- 453
I borrowed this code and it works, except for the If statement. I have seen this example numerous times and no ones had an issue. When I run it (with an empty LBIssues) it will print preview a blank page. Shouldn't it say "there is nothing to print" and not display a blank page?
Code:
Private Sub PrintBtn_Click()
Dim rng As range
Dim wks As Worksheet, ListData()
'Creates a new ws.sheet for the printout
Set wks = ThisWorkbook.Worksheets("Printout")
'Define range start for the list output
Set rng = wks.range("B2")
If LBIssues.ListCount = 0 Then
MsgBox "There is nothing in the list to print!"
Exit Sub
End If
ReDim ListData(LBIssues.ListCount - 1, LBIssues.ColumnCount - 1)
ListData() = LBIssues.List()
wks.Cells.Clear
wks.range(rng, rng.Offset(UBound(ListData), 6)).Value = ListData()
Application.ScreenUpdating = False
'Keeps ws.Printout visible
wks.Visible = xlSheetVisible
Unload ufEditIssues
wks.PrintPreview
'wks.Visible = xlSheetHidden
Application.ScreenUpdating = True
End Sub