Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Generating sequential invoice numbers
I create invoices in Excel and would like to create a macro or some other way
of inserting the next invoice number automatically. Any ideas anyone? |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Generating sequential invoice numbers
See J.E Excel pages
http://www.mcgimpsey.com/excel/udfs/sequentialnums.html -- Regards Ron de Bruin http://www.rondebruin.nl "Rod Ben" <Rod wrote in message ... I create invoices in Excel and would like to create a macro or some other way of inserting the next invoice number automatically. Any ideas anyone? |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Generating sequential invoice numbers
Hi Ron
Thanks for this but i cant seem to get it to work. I have copied the code into a module as suggested on the web site and i can get the macro to run but get an error message "ambigous name detected : Next SeqNumber". I am very much in the dark with this code. Anything obvious i am doing wrong? The code i have used is: Sub Getinvoicenumber() Public Function NextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long Const sDEFAULT_PATH As String = "C:\Documents and Settings\Rod Bennett\Desktop" Const sDEFAULT_FNAME As String = "defaultseq.txt" Dim nFileNumber As Long nFileNumber = FreeFile If sFileName = "" Then sFileName = sDEFAULT_FNAME If InStr(sFileName, Application.PathSeparator) = 0 Then _ sFileName = sDEFAULT_PATH & Application.PathSeparator & sFileName If nSeqNumber = -1& Then If Dir(sFileName) < "" Then Open sFileName For Input As nFileNumber Input #nFileNumber, nSeqNumber nSeqNumber = nSeqNumber + 1& Close nFileNumber Else nSeqNumber = 1& End If End If On Error GoTo PathError Open sFileName For Output As nFileNumber On Error GoTo 0 Print #nFileNumber, nSeqNumber Close nFileNumber NextSeqNumber = nSeqNumber Exit Function PathError: NextSeqNumber = -1& End Sub End Sub Any help greatly appreciated. Thanks. Rod "Ron de Bruin" wrote: See J.E Excel pages http://www.mcgimpsey.com/excel/udfs/sequentialnums.html -- Regards Ron de Bruin http://www.rondebruin.nl "Rod Ben" <Rod wrote in message ... I create invoices in Excel and would like to create a macro or some other way of inserting the next invoice number automatically. Any ideas anyone? |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Generating sequential invoice numbers
You copy a function in a macro and that is not correct
Read the page again and copy this function and sub in a normal module Note I use C:\ Now run the macro a few times to test Public Function NextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long Const sDEFAULT_PATH As String = "C:\" Const sDEFAULT_FNAME As String = "defaultseq.txt" Dim nFileNumber As Long nFileNumber = FreeFile If sFileName = "" Then sFileName = sDEFAULT_FNAME If InStr(sFileName, Application.PathSeparator) = 0 Then _ sFileName = sDEFAULT_PATH & Application.PathSeparator & sFileName If nSeqNumber = -1& Then If Dir(sFileName) < "" Then Open sFileName For Input As nFileNumber Input #nFileNumber, nSeqNumber nSeqNumber = nSeqNumber + 1& Close nFileNumber Else nSeqNumber = 1& End If End If On Error GoTo PathError Open sFileName For Output As nFileNumber On Error GoTo 0 Print #nFileNumber, nSeqNumber Close nFileNumber NextSeqNumber = nSeqNumber Exit Function PathError: NextSeqNumber = -1& End Function Public Sub NewClientInvoice() ThisWorkbook.Sheets(1).Range("B2").Value = NextSeqNumber("Client1.txt") End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Rod Ben" wrote in message ... Hi Ron Thanks for this but i cant seem to get it to work. I have copied the code into a module as suggested on the web site and i can get the macro to run but get an error message "ambigous name detected : Next SeqNumber". I am very much in the dark with this code. Anything obvious i am doing wrong? The code i have used is: Sub Getinvoicenumber() Public Function NextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long Const sDEFAULT_PATH As String = "C:\Documents and Settings\Rod Bennett\Desktop" Const sDEFAULT_FNAME As String = "defaultseq.txt" Dim nFileNumber As Long nFileNumber = FreeFile If sFileName = "" Then sFileName = sDEFAULT_FNAME If InStr(sFileName, Application.PathSeparator) = 0 Then _ sFileName = sDEFAULT_PATH & Application.PathSeparator & sFileName If nSeqNumber = -1& Then If Dir(sFileName) < "" Then Open sFileName For Input As nFileNumber Input #nFileNumber, nSeqNumber nSeqNumber = nSeqNumber + 1& Close nFileNumber Else nSeqNumber = 1& End If End If On Error GoTo PathError Open sFileName For Output As nFileNumber On Error GoTo 0 Print #nFileNumber, nSeqNumber Close nFileNumber NextSeqNumber = nSeqNumber Exit Function PathError: NextSeqNumber = -1& End Sub End Sub Any help greatly appreciated. Thanks. Rod "Ron de Bruin" wrote: See J.E Excel pages http://www.mcgimpsey.com/excel/udfs/sequentialnums.html -- Regards Ron de Bruin http://www.rondebruin.nl "Rod Ben" <Rod wrote in message ... I create invoices in Excel and would like to create a macro or some other way of inserting the next invoice number automatically. Any ideas anyone? |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
Generating sequential invoice numbers
Hi Ron
Works great! Many thanks for your time. Have a good weekend. Rod "Ron de Bruin" wrote: You copy a function in a macro and that is not correct Read the page again and copy this function and sub in a normal module Note I use C:\ Now run the macro a few times to test Public Function NextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long Const sDEFAULT_PATH As String = "C:\" Const sDEFAULT_FNAME As String = "defaultseq.txt" Dim nFileNumber As Long nFileNumber = FreeFile If sFileName = "" Then sFileName = sDEFAULT_FNAME If InStr(sFileName, Application.PathSeparator) = 0 Then _ sFileName = sDEFAULT_PATH & Application.PathSeparator & sFileName If nSeqNumber = -1& Then If Dir(sFileName) < "" Then Open sFileName For Input As nFileNumber Input #nFileNumber, nSeqNumber nSeqNumber = nSeqNumber + 1& Close nFileNumber Else nSeqNumber = 1& End If End If On Error GoTo PathError Open sFileName For Output As nFileNumber On Error GoTo 0 Print #nFileNumber, nSeqNumber Close nFileNumber NextSeqNumber = nSeqNumber Exit Function PathError: NextSeqNumber = -1& End Function Public Sub NewClientInvoice() ThisWorkbook.Sheets(1).Range("B2").Value = NextSeqNumber("Client1.txt") End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Rod Ben" wrote in message ... Hi Ron Thanks for this but i cant seem to get it to work. I have copied the code into a module as suggested on the web site and i can get the macro to run but get an error message "ambigous name detected : Next SeqNumber". I am very much in the dark with this code. Anything obvious i am doing wrong? The code i have used is: Sub Getinvoicenumber() Public Function NextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long Const sDEFAULT_PATH As String = "C:\Documents and Settings\Rod Bennett\Desktop" Const sDEFAULT_FNAME As String = "defaultseq.txt" Dim nFileNumber As Long nFileNumber = FreeFile If sFileName = "" Then sFileName = sDEFAULT_FNAME If InStr(sFileName, Application.PathSeparator) = 0 Then _ sFileName = sDEFAULT_PATH & Application.PathSeparator & sFileName If nSeqNumber = -1& Then If Dir(sFileName) < "" Then Open sFileName For Input As nFileNumber Input #nFileNumber, nSeqNumber nSeqNumber = nSeqNumber + 1& Close nFileNumber Else nSeqNumber = 1& End If End If On Error GoTo PathError Open sFileName For Output As nFileNumber On Error GoTo 0 Print #nFileNumber, nSeqNumber Close nFileNumber NextSeqNumber = nSeqNumber Exit Function PathError: NextSeqNumber = -1& End Sub End Sub Any help greatly appreciated. Thanks. Rod "Ron de Bruin" wrote: See J.E Excel pages http://www.mcgimpsey.com/excel/udfs/sequentialnums.html -- Regards Ron de Bruin http://www.rondebruin.nl "Rod Ben" <Rod wrote in message ... I create invoices in Excel and would like to create a macro or some other way of inserting the next invoice number automatically. Any ideas anyone? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
sequential invoice numbering | Excel Worksheet Functions | |||
AUTOMATIC INVOICE NUMBERS | Excel Discussion (Misc queries) | |||
sequential numbers on invoices | Excel Worksheet Functions | |||
How do I take two columns of sequential numbers and insert spaces | Excel Discussion (Misc queries) | |||
automatic order or invoice numbers | Excel Worksheet Functions |