How do I generate automatic invoice numbers in excel

G

Guest

I want to be able to generate the next sequential number of an invoice when I
open excel to type/print a new invoice.
 
I

icestationzbra

some wise soul had shared this in some other post, i am posting it here
seemingly, it helps create automatic sequencing in cell A1 on Sheet1.

Private Sub Workbook_Open()
Const DEFAULTSTART As Integer = 1
Const MYAPPLICATION As String = "Excel"
Const MYSECTION As String = "myInvoice"
Const MYKEY As String = "myInvoiceKey"
Const MYLOCATION As String = "A1"
Dim regValue As Long

With ThisWorkbook.Sheets(1).Range(MYLOCATION)
If .Text <> "" Then Exit Sub
regValue = GetSetting(MYAPPLICATION, MYSECTION, _
MYKEY, DEFAULTSTART)
.Value = CStr(regValue)
SaveSetting MYAPPLICATION, MYSECTION, MYKEY, regValue + 1
End With
End Su
 
A

alainB

Hi,

When I print an invoice, the data of that invoice is saved on my dat
sheet, one line per invoice and many columns, one for each data of th
invoice. The first column being for the invoice number.

To get the next sequential number I find the last line used of the dat
sheet and it will be the value of the column A of that line plus one.

To find the last row use this formula from Ron De Bruin:

Sub test()
MsgBox LRow(ActiveSheet) + 1
End Sub

Function LRow(sh As Worksheet)
On Error Resume Next
LRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function

It is working great for that purpose.

Alai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top