You need someway of storing the last number used and each time assign the next one. You could use the VB functions SaveSetting and GetSetting to store this in the Registry.
There's some stuff on this at
http://j-walk.com/ss/excel/eee/eee020.txt
about creating a unique seqeuntial number for each instance of a template. Should give you some ideas.
Gary
You can plug this line of code into your existing print macro, assuming your invoice is in A1 and you want to increment the invoice number by 1:
Range("A1").Value = Range("A1").Value + 1
Tom U
Try this:
Sub Macro1()
Dim Cntr, InvoiceNumber As Integer
Cntr = FreeFile()
Open "invoicenm.txt" For Input As #Cntr
Input #Cntr, InvoiceNumber
Range("B1") = InvoiceNumber
Close #Cntr
Open "InvoiceNm.Txt" For Output As #Cntr
Write #Cntr, InvoiceNumber + 1
Close
End Sub
This creates a text file. The first part opens the file and put the number into a variable. (It does not allow you to put the number directly onto the spreadsheet.) The second part saves the next invoice number into the file.
You may have to run the later part once initially to set up the file.
Thanks everybody!!
I went witht he solution from Tom U.
Single line of code
Works great!!
Scott