Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a form in Excel that I have to print a zillion of. The problem is each print out has to have a unique form number for tracking purposes. The number is incremental from 0001 (or just 1 would do) to 9999 etc. How do I make the cell that holds the number automatic to increase the number per printed page?
I have got the following code that works, but i have to press enter each time to print the next numbered page - whereas I want to set the mcro to print 100 or so and then walk away while the printer chugs away.
Sub IncrementandPrint()
Dim iNumber As Integer
Dim iNewNumber As Integer
Dim strCharacters As String
sPrint = InputBox("Enter number of times to Print:")
' Put the Actual cell in here that needs changing!
Range("K1").Select
'Print the first copy with current data.
If Not IsNumeric(sPrint) Then
MsgBox "Number to Print MUST be numeric!"
Exit Sub
Else
'Print the first copy....
ActiveWorkbook.PrintOut 'Many Options here!
iNumber = GetNumericValue(ActiveCell.Value)
If iNumber <= 0 Then
strLeftValue = ""
Else
strLeftValue = Left(ActiveCell.Value, Len(ActiveCell.Value) - iNumber)
End If
iNewNumber = CInt(Right(ActiveCell.Value, iNumber))
For i = 1 To CInt(sPrint) ' Start at 2 since the 1st 1 is printed above...
iNewNumber = iNewNumber + 1
ActiveCell.Value = strLeftValue & CStr(iNewNumber)
ActiveWorkbook.PrintOut 'Many Options here!
MsgBox strLeftValue & CStr(iNewNumber)
Next
End IfEnd Sub
Function GetNumericValue(s As String) As Integer
'This Sub returns the Amount of characters from the right of a String that are numeric
'Assuming that the characters are always to the left here:
Dim iLoopCounter As Integer
iLoopCounter = 0
For i = Len(ActiveCell.Value) To 1 Step -1
iLoopCounter = iLoopCounter + 1
If Not IsNumeric(Right(ActiveCell.Value, iLoopCounter)) Then Exit For
NextGetNumericValue = iLoopCounter - 1
End Function
*****
Any help would be much appreciated!bob999

Thanks for the quick reply Michael. Unfortunately that macro does not increment the page number - it simply prints the same form with the same number "n" times (the same as a normal "File Print").
If I set the number of prints to 10 I want to get ten pages numbered consecutively from 1 to 10.
Bob
bob999

Michael - my apologies, I made a few changes to the macro and it now works fine!!
My only remaining problem is that it always starts from number "1", whereas if I print sheets regularly I want to resume from the last number that I left off from at my last session.
The macro now looks like this (my next print number is stored in cell K1)
Sub PrintCopies_ActiveSheet()
Dim CopiesCount As Long
Dim CopieNumber As Long
CopiesCount = Application.InputBox("How many Copies do you want?", Type:=1)
For CopieNumber = 1 To CopiesCount
With ActiveSheet
'number in cell K1 (prints "n")
.Range("K1").Value = CopieNumber
'number in cell K1 (prints "n of z")
'.Range("K1").Value = CopieNumber & " of " & CopiesCount
'number in the footer (prints "n of z")
'.PageSetup.LeftFooter = CopieNumber & " of " & CopiesCount
'Print the sheet
.PrintOut
End With
Next CopieNumber
End Subbob999

I'm not too familiar with VB, so I can't provide any code. But, I can help with the logic.
Instead of making your CopieNumber loop go from 1 to copiesCount you first need to grab the value of cell K1 and make your CopieNumber loop go from 1+K1 to copiesCount+K1.
Michael J

Hi Michael,
Many thanks for getting back to me again on this query. I'm no VB expert myself, so have asked Rob DeBruin (author of the original VB code) if he can help out.Thanks again for your time and effort!!
bob999

![]() |
audio driver emulating a ...
|
Mail Merge using VB
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |