Close this search box.

Generating invoice numbers using excel [reader questions]



Michelle, Who is a sweet lady and regular reader of the blog sent me this question via e-mail. (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 non-store 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.

Invoice Numbers in ExcelIf I understand it correct, Michelle is looking for something like this:

So, in order to generate such numbers,

  1. First we will make 2 named ranges – customer_list and ncf_numbers. You know what they mean.
  2. Now, we will enter the customer name in column B, and based on that we will fetch RNC number in column C.
  3. For this, we will use VLOOKUP () formula. The simplest formula looks like this: VLOOKUP(B5,customer_list,4,FALSE)
  4. 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))
  5. 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*”))).
  6. Above formula simple fetches the nth NCF number from the named range ncf_numbers if RNC number is not blank.
  7. 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


Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Excel School made me great at work.

– Brenda

Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

Announcing Power BI Dashboard Contest 2024

Announcing Power BI Dashboard Contest (win $500 prizes!)

Hey there, I have a SUPER exciting announcement! April is about to get a whole lot sweeter with our Power BI Dashboard Contest! Your mission, should you choose to accept it: Craft the most EPIC dashboard for the Awesome Chocolates CEO with sales & financial insights! Winners stand a chance to score up to $500 in Amazon Gift Cards, plus some serious bragging rights!

17 Responses to “Generating invoice numbers using excel [reader questions]”

  1. Martin says:

    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.



  2. Chandoo says:

    @Martin: Good suggestion... I didnt think about it when making the named ranges.

    @all.. you can make named ranges dynamic using OFFSET()

  3. Michelle says:

    Thank you soooo much Chandoo... as always, you are a life saver!! All my best for you and your family 😀

  4. Clint says:

    Please, what did you use to make the mini movie of Excel for this post?

  5. iiuniveadds says:

    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.

    • Chandoo says:

      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... 🙂

  6. Manik says:

    I can't able to manage the named ranges, how can I control them in a different shee. Please help me.

  7. mdakram says:

    just i want to know how can we get dropdown filter in cell,,pleas suggest

  8. Chandoo says:

    @Manik .. are you still stuck.. ?

    @Mdakram.. Check this out: http://chandoo.org/wp/2008/08/07/excel-add-drop-down-list/

  9. Ron T says:

    Great site. I've learned more in the past week than in the privious 2 years
    thank You

    Ron T

  10. Chandoo says:

    @Ron T: that is very sweet. Thank you 🙂

  11. kadri guler says:

    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/Auto-Invoice-Number.rar.html

  12. Manjunath says:

    Dear Chandoo,
    What is the difference between your formula and mine


    • Hui... says:

      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.

  13. Latrina Popkin says:

    Great article! I wonder if this would also be possible in The Netherlands?

Leave a Reply