This was very helpful! Is there a way to print multiple pages? For example, if cell A1 = 5, print pages 1-5.
-
To post as a guest, your comment is unpublished.Hi Ryan,
If you want to print consecutive pages such as 1-5 in a worksheet based on a cell value, please specify a cell such as A1 as Text formatting, type 1-5 into it, keep this cell selecting, and then run the below VBA code.
Sub Print_Pages()
Dim xPage As String
Dim xYesorNo As Integer
Dim xI As String
Dim xPArr() As String
Dim xIS, xIE, xF, xNum As Integer
xPage = ActiveCell.Value
xYesorNo = MsgBox("Ready to print page" & xPage & " ", vbYesNo, "Kutools for Excel")
If xYesorNo = vbYes Then
xPArr() = Split(xPage, "-")
If UBound(xPArr) = 0 Then
If IsEmpty(xPage) And IsNumeric(xPage) Then
MsgBox "Please specify a cell and enter a page in cell"
Exit Sub
End If
xNum = Int(xPage)
ActiveSheet.PrintOut from:=xNum, To:=xNum, preview:=True
ElseIf UBound(xPArr) = 1 Then
On Error GoTo Err01
xIS = Int(xPArr(0))
xIE = Int(xPArr(1))
If xIS < xIE Then
For xF = xIS To xIE
ActiveSheet.PrintOut from:=xF, To:=xF, preview:=True
Next
Else
For xF = xIE To xIS
ActiveSheet.PrintOut from:=xF, To:=xF, preview:=True
Next
End If
Else
MsgBox "Please enter the valid data", vbOKOnly, "Kutools for Excel"
Exit Sub
End If
Else
Exit Sub
End If
Exit Sub
Err01:
MsgBox "Please enter the correct page scope", vbOKOnly, "Kutools for Excel"
End Sub-
To post as a guest, your comment is unpublished.Thank you. I have the same issue I want to print pages based on cell value. Lets say variable changes i.e page 1-5 and then some time 2-6. So I have a field which will calculate and will put that in text format as suggested.But for some reason it doesnt work for me. It doesnt prints any pages.Can you please advise
-