VBA print x number of copies based on number specified in a cell

chelseasikoebs

Board Regular
Joined
Mar 9, 2009
Messages
59
I have two worksheets that we print off weekly. However, the quantity of pages we print each week changes. I would like to have a cell that asks for the number of copies to print, then after my existing script runs through changes on the sheet, it'll automatically print x number of copies that was specified in that cell. Any ideas?
 

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,795
Office Version
  1. 2019
Platform
  1. Windows
Should be easy if you just add one line to your code:

Code:
ActiveSheet.Printout  Copies:=Range("A1").Value

Or
Code:
For x = 1 to Range("A1").Value
    ActiveSheet.Printout
Next x

I suppose you may want to add some validation - is A1 a number, is it greater than 0? Is it less than a maximum allowed number? Or have the number of copies entered at runtime with an input box.
 

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
4,714
Hi there,

Run the following on the sheet in question. It will print that sheet the number of times that is in cell A2 (change as required):

Code:
Sub Macro1()

    With ActiveSheet
        .PrintOut Copies:=Range("A2").Value
    End With
    
End Sub

HTH

Robert
 

chelseasikoebs

Board Regular
Joined
Mar 9, 2009
Messages
59
Code:
Sub Macro1()

    With ActiveSheet
        .PrintOut Copies:=Range("A2").Value
    End With
    
End Sub
HTH

Robert[/QUOTE]


I get a runtime error 1004 when I add this to the end of my other script. If I run it as a separate macro, it works. Why would that be?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,911
Messages
5,598,819
Members
414,260
Latest member
joishe

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
Top