Generating invoice numbers using excel [reader questions]
Michelle, Who is a sweet lady and regular reader of the blog sent me this question via email. (aside: why is she a sweet lady? Because she saw the new cell post and sent me pics of her son and told Jo and me are about to encounter most amazing experiences of our lives ðŸ™‚ )
I handle the invoices we give to our customers (we build and sell furniture), but sometimes such customers can be stores or just regular folks that come directly to us.
For the stores I have to give an invoice that has a NCF number which is a tax related number that increases the cost in 16% but stores require this number which must be unrepeatable. Each company has a “list” of numbers that they can provide their customers. Regular customers (not stores) have no interest in this number, obviously trying to avoid the 16% increase in the price!
So far what I did was create a database of our customers with the basic info of each one. Many of our customers keep buying so this way I just have to place myself in the invoice and select from a list and with a simple vlookup I get the rest of the customer’s information: phone, address and RNC number.
Now… the RNC is the number that tells me if it’s a store or not. Stores must have their registration number (RNC) in order to receive invoices with NCF (boring, I know… I’m gonna get to the point in a sec). Ok, so if I choose my dear customer “Chandoo Enterprises” and this store has RCN, then I automatically need for the invoice to pull form “my list” of government assigned NCF numbers, the next one in line. If in my previous invoice (say invoice 1455) to another store I used NCF number A010010010100000002 (that’s how they look) for Chandoo Enterprises invoice #1456 I am going to need the next number in line A010010010100000003 and so on. Now, say that my next invoice (1457) is not to a store but to John Doe, for him I don’t want an NCF number to show.
I keep thinking that there’s a very stupid and simple way to do this but I just can’t nail it!! My problem is to get to a formula that will work only when the RNC field has information and therefore avoiding NCF numbers to appear on nonstore customers (not so complicated I think) and that it chooses the next NCF number in line, no repeating… this is the part that I have no idea how to do!! Is there a way to solve this without using VBA? VBA is scary!! Hehehe
Okay, that is a big question, but may be we can come up with a small solution for it.
If I understand it correct, Michelle is looking for something like this:
So, in order to generate such numbers,
 First we will make 2 named ranges – customer_list and ncf_numbers. You know what they mean.
 Now, we will enter the customer name in column B, and based on that we will fetch RNC number in column C.
 For this, we will use VLOOKUP () formula. The simplest formula looks like this: VLOOKUP(B5,customer_list,4,FALSE)
 But, simplest formula also has problems – it doesn’t handle errors and can return 0 when the RNC number field is blank. So we will add some fat to it, mainly on the front side. It now looks like this: =IF(ISERROR(VLOOKUP(B5,customer_list,4,FALSE)),””, VLOOKUP(B5,customer_list,4,FALSE))
 In the third column, we will fetch the next available NCF number if the customer has an RNC. For this, we use a simple IF() and COUNTIF() formulas along with INDEX() formula. We write: =IF(OR(C5=””,C5=0),””,INDEX(ncf_numbers,COUNTIF($C$5:C5,”RNC*”))).
 Above formula simple fetches the nth NCF number from the named range ncf_numbers if RNC number is not blank.
 That is all.Â We now have a simple logic to generate invoice numbers that suit tax authority’s whims and fancies.
Download the example workbook:
You can download the excel tutorial workbook and see how you can generate such invoice numbers yourself.
More material if you are getting stuck with formulas
50+ Excel Formulas – Explained in plain English, Excel formula tutorials, Excel array formula examples
Hello Awesome...
My name is Chandoo. Thanks for dropping by. My mission is to make you awesome in Excel & your work. I live in Wellington, New Zealand. When I am not F9ing my formulas, I cycle, cook or play lego with my kids. Know more about me.
I hope you enjoyed this article. Visit Excel for Beginner or Advanced Excel pages to learn more or join my online video class to master Excel.
Thank you and see you around.

Leave a Reply
« 2 Great Pieces of Advice for Chart Makers, Dashboard Designers and Story Tellers Everywhere  Use burn down Charts in your project management reports [bonus post] » 
17 Responses to “Generating invoice numbers using excel [reader questions]”
Dear Chandoo,
just saw the xl file, and noticed that named ranges are static. A good approach would be to make them dynamic, so blank cells won't appear on the dropdown combos.
Rgds.
Martin
@Martin: Good suggestion... I didnt think about it when making the named ranges.
@all.. you can make named ranges dynamic using OFFSET()
Thank you soooo much Chandoo... as always, you are a life saver!! All my best for you and your family ðŸ˜€
Please, what did you use to make the mini movie of Excel for this post?
@Clint.. I use Camtasia Studio (http://www.techsmith.com/camtasia.asp ) to make the screencasts in my posts. It is a very good software. If you are into publishing, you might want to give it a try.
Hi. Great stuff. I actually stumbled upon your blog accidentally but was amazed by its content. The information was
really good and i would love to come back often. So I have given link to your blog from my blog. Same thing is
expected from your side for good colleboration & mutual gain.
Thanks iiuniveadds. I am flattered. However I do not link to blogs just like that. I link to excel and charting related websites every now and then if the content is cool. Let me know if there is something on your site that matches the bill... ðŸ™‚
I can't able to manage the named ranges, how can I control them in a different shee. Please help me.
Dear
chandu
just i want to know how can we get dropdown filter in cell,,pleas suggest
@Manik .. are you still stuck.. ?
@Mdakram.. Check this out: http://chandoo.org/wp/2008/08/07/exceladddropdownlist/
Great site. I've learned more in the past week than in the privious 2 years
thank You
Ron T
@Ron T: that is very sweet. Thank you ðŸ™‚
New my auto invoice number example.
Auto numbering with txt
Auto total
Price List
example in http://www.netmerkez.wordpress.com/
view from : http://hotfile.com/dl/139670745/2ff1e4b/AutoInvoiceNumber.rar.html
Dear Chandoo,
What is the difference between your formula and mine
=IF(ISERROR(VLOOKUP(B9,customer_list,4,FALSE)),"",VLOOKUP(B9,customer_list,4,FALSE))
=IFERROR(VLOOKUP(B9,customer_list,4,FALSE),"")
Regards
@Manjunath
The First formula uses the =IF(ISERROR( functions
This has been available in all Excel versions.
The Second formula uses the =IFERROR( Function
Iferror was only introduced in Excel 2007 and hence cannot be used in older versions of Excel.
Both formulas return the same result except that the second formula is more efficient. But unless you have many thousands of these cells with similar formulas you will not notice a speed difference.
hmmm...ok
thanks for the prompt reply..
Great article! I wonder if this would also be possible in The Netherlands?