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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,627
Office Version
2013
Platform
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,587
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,095,541
Messages
5,445,083
Members
405,315
Latest member
ao5835403

This Week's Hot Topics

Top