Print preview multiple sheet into one Print Job (VBA)

jaeremata

New Member
Joined
Jan 20, 2021
Messages
24
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
have a check box that has 4 sheets. It's working if I select 1 sheet and it's doing it's job.

But I'm having issue when 2 checkbox is selected. It open separate print job. What I want to happen is when when 2 sheets(or more) are selected on the checkbox, it will do a print preview but on one print job.

I don't know what I'm missing, please kindly point me or guide me to correct what needs to be done.

Here's my sample code:

Private Sub CommandButton1_Click()
If Me.cbSH1 = True Then
ThisWorkbook.Sheets("NC Performance").PrintPreview
End If

If Me.cbSH2 = True Then
ThisWorkbook.Sheets("8D Performance").PrintPreview
End If

If Me.cbSH3 = True Then
ThisWorkbook.Sheets("Attack Plan").PrintPreview
End If

If Me.cbSH4 = True Then
ThisWorkbook.Sheets("Plant Overview").PrintPreview
End If

If Me.cbSH1 And Me.cbSH2 = True Then
Sheets(Array("NC Performance", "8D Performance")).PrintPreview
End If
End Sub
 
I've tried to used it and now, It returns another error.

1611218094827.png
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Can you grab a screen capture of the error from the second one showing the error message and the line that it highlights please.
I can't see that the code should return the exact same error unless you have changed the names of the checkboxes.
 
Upvote 0
VBA Code:
Private Sub CommandButton1_Click()
Dim x&, c&, SheetArray() As String
Dim AllSheets(): AllSheets = Array("NC Performance", _
    "8D Performance", "Attack Plan", "Plant Overview")
For x = 1 To 4
   If Me.Controls("cbSH" & x) = True Then
        ReDim Preserve SheetArray(c)
        SheetArray(c) = AllSheets(x - 1)
        c = c + 1
    End If
Next
On Error resume Next
Sheets(SheetArray).PrintPreview
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top