Multiple print copies with arrays

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
I am using the below code on a userform that looks at which checkboxes the user ticked, which correspond the sheet names in the active workbook. Then prints out the sheets they selected.

My problem is that I would also like the user to be able to use the userform to enter the number of copies they want for a particular sheet into a textbox. With the script below I cant figure out how to use my print array to include multiple copies of sheets that the user wants.

Can this be done or does it need to be a separate printout statement?

Code:
Dim Sh As Worksheet
    Dim arr() As String
    Dim N, S As Integer
    N = 0
Singles = Array(ckNA, ckOut, ckAsg, ckCP, ckHJ)
CheckBoxing = Array(ckMedLog, ckRespLog, ckBS, ckOutLog, ckPulseLog, ckBPLog, ckBSplus, ckSkinLog) 'These are the checkbox objects I would like the user to have the ability to make multiple copies of
Text = Array(n1, n2, n3, n4, n5, n6, n7, n8) ' This is the textbox array that correspond with the checkbox objects above


For Each Sh In ActiveWorkbook.Worksheets
    For S = 0 To UBound(Singles)
        If Singles(S).Value = True And Singles(S).Caption = Sh.Name Then
            N = N + 1
            ReDim Preserve arr(1 To N)
            arr(N) = Sh.Name
        End If
    Next S
Next Sh

    With ActiveWorkbook
        .Worksheets(arr).PrintOut
    End With

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
So I was able to make some headway with the below script but even when the script is being directed to print multiple copies it only prints one copy. What am I doing wrong here?


Code:
Private Sub CommandButton1_Click()

    Dim Sh As Worksheet
    Dim wks As Worksheet
    Dim arr() As String
    Dim arr2() As String
    Dim N, T, S, M, CopyNumber, CopyCount As Integer
    N = 0
    T = 0
Singles = Array(ckNA, ckOut, ckCS, ckCP, ckAsg)
CheckBoxing = Array(ckHJ, ckPN, ckAR, ckMF, ckMedLog, ckRespLog, ckBS, ckOutLog, ckPulseLog, ckBPLog, ckBSplus, ckSkinLog)
Text = Array(n9, n10, n11, n12, n1, n2, n3, n4, n5, n6, n7, n8)
For Each Sh In ActiveWorkbook.Worksheets
    For S = 0 To UBound(Singles)
        If Singles(S).Value = True And Singles(S).Caption = Sh.Name Then
            N = N + 1
            ReDim Preserve arr(1 To N)
            arr(N) = Sh.Name
        End If
    Next S
Next Sh

For Each wks In ActiveWorkbook.Worksheets
    For M = 0 To UBound(CheckBoxing)
        If CheckBoxing(M).Value = True And CheckBoxing(M).Visible = True And wks.Name = CheckBoxing(M).Caption Then
            CopyCount = 0
            CopyNumber = Text(M).Value
            Do
                T = T + 1
                CopyCount = CopyCount + 1
                ReDim Preserve arr2(1 To T)
                arr2(T) = wks.Name
            Loop Until CopyCount = CopyNumber
        End If
    Next M
Next wks
Application.EnableEvents = False
    With ActiveWorkbook
        .Worksheets(arr).PrintOut
        .Worksheets(arr2).PrintOut
    End With
Application.EnableEvents = True

End Sub
 
Upvote 0
The only I could get this to work was with multiple print out statements. It is the only way to specify a print order and quantity for each page that needs to be printed.
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,631
Members
449,241
Latest member
NoniJ

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