VBA

Genetu

New Member
Joined
Apr 20, 2022
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
Hello guys? is there any VBA code to print a selected range (A1:J25") two times on a single piece of paper?
 

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).
If it were me, I would probably open a new workbook, copy over my range to that new workbook twice, print it, and then close the workbook without saving it.

You can probably get most of the VBA code you need for that by turning on the Macro Recorder and record yourself performing those steps manually.
If you do that and need a little help modifying or cleaning-up the recorded code afterwards, post your recorded code here along with a description of what you need changed.
 
Upvote 0
VBA Code:
Option Explicit

Sub PrintRng()
Dim numrow As Long
Dim i As Long
Dim runmacro
    runmacro = Application.InputBox("How many print copies?", "Enter a number", , , , , , 1)
    
    If IsNumeric(numrow) Then
        For i = 1 To runmacro
            Range("A1:J25").PrintOut
        Next i
    End If
End Sub
 
Upvote 0
I will do that, and return tomorrow after recording the macro. Thank you, Joe.
 
Upvote 0
VBA Code:
Option Explicit

Sub PrintRng()
Dim numrow As Long
Dim i As Long
Dim runmacro
    runmacro = Application.InputBox("How many print copies?", "Enter a number", , , , , , 1)
   
    If IsNumeric(numrow) Then
        For i = 1 To runmacro
            Range("A1:J25").PrintOut
        Next i
    End If
End Sub
Logit,

Look at the requirements again.
They are not looking to print two separate sheets of paper.
They want the same range print twice on a single sheet of paper.
 
Upvote 0
The following first creates a TEMP sheet to paste to ... then it copies the specified range and pastes it twice to the TEMP sheet. The TEMP sheet is
printed and then deleted.

As indicated in the code, you may be able to utilize a larger font depending upon your printer. In order to get all of the data onto a single sheet
on my printer I had to select the FONT indicated.

VBA Code:
Option Explicit

Sub copypaste()

    Dim ScreenUpdating As Boolean
    Dim PasteSht As Worksheet
    Dim Rg As Range
    Dim Txt As String
    Dim i As Integer
    
    On Error Resume Next

    Sheets.Add.Name = "Temp"

    Txt = ActiveWindow.RangeSelection.Address
    Set Rg = Sheets("Sheet1").Range("A1:J25") '<-- change range to copy here
    
    If Rg Is Nothing Then Exit Sub
    Set PasteSht = Worksheets("Temp")
    
    Application.ScreenUpdating = False
    
    Rg.Copy
    
    For i = 1 To 2
        PasteSht.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    Next
    
    
    Application.CutCopyMode = False
    
    Worksheets("Temp").Activate
    Range("A1").Select
    ActiveSheet.Cells.Font.Name = "Calibri"
    ActiveSheet.Cells.Font.Size = 6         '<--- You may be able to use a larger font depending on your printer
    
    With Worksheets("Temp")
        .PageSetup.Orientation = xlLandscape
        .PageSetup.PrintArea = "$A$1:$J$51"
        .FitToPagesWide = 1
        .FitToPagesTall = 1
        .PageSetup.PrintArea = .UsedRange.Address
        .PrintOut
    End With
    
    Application.ScreenUpdating = True

    Application.DisplayAlerts = False
    Sheets("Temp").Delete
    Application.DisplayAlerts = True

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,226,737
Messages
6,192,736
Members
453,752
Latest member
Austin2222

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