auto increment invoice number/ID ?

anamo

New Member
Joined
Feb 3, 2014
Messages
26
hi all
the attached Template excel file has cell called "Invoice no."
I wan that cell to be automatically updated to give each invoice unique number

like S1000 and it ill be S1001 for the next invoice but i have no idea how this will be done


I tried to set it to be data and time using
=now() but the problem is that it shown by this format 7/31/14 10:59
i tried to covert it to this format 1407311059 but I fail


so please anyone can help ! :confused:
 
Okay done but this wont work with template excel files am I right ??
if yes then what you suggest to do that


thanks

general file type is .xlsx (from office 2007) .xlsm or .xlsb also excel files. But when you have macro code in the module you have to save wb as .xlsm or .xlsb type.
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
but I think that it'll be better to increase invoice number before printing or after archiving (registering).

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
[A1] = [A1] + 1
[A1].NumberFormat = """S""0"
End Sub
 
Upvote 0
but I think that it'll be better to increase invoice number before printing or after archiving (registering).

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
[A1] = [A1] + 1
[A1].NumberFormat = """S""0"
End Sub

yea it better the whole idea is not really accurate enough since u can save anytime not just when u close the file printing is more accurate ... and sadly macros wont works with templates :S
 
Upvote 0
yea it better the whole idea is not really accurate enough since u can save anytime not just when u close the file printing is more accurate ... and sadly macros wont works with templates :S

btw what do you mean by after archiving (registering) please
 
Upvote 0
btw what do you mean by after archiving (registering) please

printing invoice details to pdf or inserting another base sheet rows to keep all invoice records
P.S : to avoid about macrophobia just save your file as .xlsb and that is all.
 
Upvote 0
hi all
i come up with the following solution which has extra amazing thing it will save the file with the ID name
but i got problem with handling file exist exception :S

like if exception thrown then do the following
Range("E4").Value = Range("E4").Value + 1
but how to catch the exception ????




Code:
Sub nxt_invoice()
Range("E4").Value = Range("E4").Value + 1
Range("A8:E21").ClearContents
Range("A1").ClearContents
Range("c2:c5").ClearContents
End Sub


Sub save_invoice()
Dim newfn As Variant
' copy invoice to a new workbook
ActiveSheet.Copy
newfn = "D:\Invoice\Inv" & Range("E4").Value & ".xlsx"
ActiveWorkbook.SaveAs newfn, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
nxt_invoice
End Sub
 
Upvote 0
hi all
i come up with the following solution which has extra amazing thing it will save the file with the ID name
but i got problem with handling file exist exception :S

like if exception thrown then do the following
Range("E4").Value = Range("E4").Value + 1
but how to catch the exception ????




Code:
Sub nxt_invoice()
Range("E4").Value = Range("E4").Value + 1
Range("A8:E21").ClearContents
Range("A1").ClearContents
Range("c2:c5").ClearContents
End Sub


Sub save_invoice()
Dim newfn As Variant
' copy invoice to a new workbook
ActiveSheet.Copy
newfn = "D:\Invoice\Inv" & Range("E4").Value & ".xlsx"
ActiveWorkbook.SaveAs newfn, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
nxt_invoice
End Sub

use

Code:
ThisWorkbook.Save

at the end of the line of save_invoice() to save your workbook.
(but it'll better to save your wb as .pdf)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,574
Members
449,173
Latest member
Kon123

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