Excel - A macro to perform the automatic numbering of invoices

August 2017



Issue


I store my invoices under Excel, but I have to manually assign a new number to each of them every time.
Is it possible to have automatic numbering using a macro?

Solution


This is a macro that can increment (for example) an invoice number. In this macro, the number is displayed in cell "A1", but it can be changed to your convenience.

Sub Increment_invoice()   

Dim num As Integer   
Range("A1").Select   
num = Range("A1").Value   
num = num + 1   
Range("A1").Value = num   

End Sub 



You also want to add these lines to the end of a macro so that every time you print your invoice, the next one will be incremented automatically as follows:
Sub PRINT()   

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True   
Dim num As Integer   
Range("A1").Select   
num = Range("A1").Value   
num = num + 1   
Range("A1").Value = num   

End Sub

Related


Published by aakai1056. Latest update on November 21, 2011 at 11:34 AM by aakai1056.
This document, titled "Excel - A macro to perform the automatic numbering of invoices," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).