Macro to automatically print invoices - the number of invoices changes daily

helpmehelen

New Member
Joined
Jun 13, 2018
Messages
3
I have the following code to automatically print invoices. I have the print area sorted and it runs ok but i need to change the 300. The number of invoices i need to print each day and I don't know what to replace the '300' with so it prints only the data i need, rather than 300 sheets each day.
On the first tab on my workbook i have a code to hide all rows i dont need on that day so could i link my code to this to pick up the number of rows to include maybe?

Dim i As Integer
For i = 1 To 300


Range("A2").Select
ActiveCell.FormulaR1C1 = i
Range("A1:AA55").Select
Selection.PrintOut Copies:=1


Next i
End Sub

Any help would be greatly appreciated- i am pretty new to coding so apologies if my explanation isnt too good!!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
We need to determine how we know what the 300 should be... what determines the number of invoices to print? It may be worth posting a copy of the workbook in question (without sensitive data of course).
 
Upvote 0
The number that will replace the 300 on a daily basis is picked up from another tab in the same workbook - cell M22 on a tab called company data
 
Upvote 0
Could you use...

Code:
Sub YourRoutine()

[COLOR=#333333]Dim i As Integer[/COLOR]
[COLOR=#333333]For i = 1 To Sheets("Company data").Range("M22").value[/COLOR]


[COLOR=#333333]Range("A2").Select[/COLOR]
[COLOR=#333333]ActiveCell.FormulaR1C1 = i[/COLOR]
[COLOR=#333333]Range("A1:AA55").Select[/COLOR]
[COLOR=#333333]Selection.PrintOut Copies:=1[/COLOR]


[COLOR=#333333]Next i[/COLOR]
[COLOR=#333333]End Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,364
Messages
6,124,507
Members
449,166
Latest member
hokjock

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