shadow

Excel Formula To Generate 13 Digit Barcode Check Digit

I was preparing data in an Excel spreadsheet for import into an OpenBravoPOS database, and needed to generate check digits for my custom barcodes.  So here’s the Excel formula I came up with to generate a 13-digit barcode check digit.

OpenBravoPOS

I’ve been tinkering with OpenBravoPOS for a while – it’s an exciting learning curve.

What isn’t so exciting is the process of stock taking and click-click-clicking your way a thousand times around the OpenBravoPOS interface.

No fault of OpenBravoPOS, it’s just when you’re starting from scratch with over 500 products (and that’s a smallish inventory), it gets a bit tedious.

An easy solution is to set up the database structure in Excel. Then, with a little preparation, you can export the data from Excel and import it in to your database.

Barcodes Not in the Wild

To make products scanable, they need barcodes. Some have, some don’t, so I created barcodes for all the products.

Manufacturer of products get their barcodes through proper channels, but in my closed environment where their only purpose is to identify my products when I scan them, made-up barcodes suit me fine.

I chose the EAN-13 Barcode, because OpenBravoPOS comes with a report that can convert a 13 digit number into a EAN-13 barcode image, which is ready to print.

The catch is that the 13th digit, which is a check digit, must be correct according to the EAN-13 Check Digit Formula, so you can’t just come up with any 13 numbers. For one, OpenBravoPOS won’t even generate the barcode if the check digit isn’t right.

There are websites which will generate the 13th check digit for you based on any 12 numbers you enter – and that’s fine for only a few barcodes, but when you have 500+ barcodes to generate you’d be back to click-click-clicking your way through hundreds of numbers, copy-and-pasting the check digits. Not cool.

Excel Formula for that 13-Digit Barcode Check Digit

1. You need unique strings of 12 numbers

First, I started with 12 numbers, which has to be unique – in other words each 12 digit string can only be used once in the database.

I did it like this:

  • The date made up the 1st 6 digits: 100810
  • The next 6 digits are just sequential, and Excel will sort that out, so I added 000001
  • In Excel when you drag the cell selector down, it will increment the 1 as you drag it, so every product will have a unique number. You can have 1,000,000 unique barcodes/products with this numbering system per day.

2. Finicky-but-not-complicated Check Digit Formula

In practice, the 13th digit determines whether or not your other 12 numbers in the barcode are correct. I guess this is to verify that the numbers scanned properly. For ease of demonstration, I’ll use 123456789012 as my 12 digit example number (in hindsight this just made things confusing, but nevermind).

  • Startingwith,and including, the 2nd digit, take every other digit in your 12 digit number, add them all together and times by 3
    • In my example: (2 + 4 + 6 + 8 + 0  + 2) * 3 = 66
    • In Excel use the MID() function to select the specific digits. If your 12 digit number is in cell C4, you can write MID(C4, 2, 1) – the 2 is the digit position, and the 1 indicates how many digits you want – in our case we want just 1 digit at a time, starting at position no. 2, then position no. 4, etc.
    • To perform this part of the calculation, the Excel formula looks like this:

      =(MID(C4,2,1)+MID(C4,4,1)+MID(C4,6,1)
      +MID(C4,8,1)+MID(C4,10,1)+MID(C4,12,1))*3

  • Next, take the remaining digits and add them together. The actual formula says * by 1, but how pointless is that?
    • In my example: 1 + 3 + 5 + 7 + 9 + 1 = 26
    • In Excel, use the same MID() function to select these digits.
    • This part of the calculation’s Excel formula looks like this:

      =MID(C27,1,1)+MID(C27,3,1)+MID(C27,5,1)
      +MID(C27,7,1)+MID(C27,9,1)+MID(C27,11,1)

  • Now take the individual sums of those equations, and add them together: 66 + 26 = 92 (I’m sure you know this Excel formula);
    • In case you don’t, in excel it looks like this:

      =66+26 or by cell number =C5+C6;

  • Next, round the result up to the nearest 10. Our example’s result of rounding up from 92 is 100;
    • In Excel we use the ROUNDUP() formula for this. Usually ROUNDUP is used for digits to the right of the decimal point, but we can also use it for whole numbers. It looks like this:

      =ROUNDUP(G4,-1)
      where G4 is the cell location of our un-rounded sum (92), and -1 basically just tells the function to round up to the nearest 10 (if the decimal mark is position 0, -1 means one step to the left).

  • The actual check digit is your rounded up number, minus the un-rounded sum; so 100 – 92 = 8.
  • Our 13th and check digit for this fictitious barcode is 8.
  • Lastly, automatically add your check digit to your 12 digit number with the Excel formula =C4&H4 (assuming your 12 digit number is in cell C4 and your check digit is in cell H4). The result is your 13 digit barcode: 1234567890128



If you want minimal columns in your Excel spreadsheet, then you need just 1 column with your 12 digit number (in my case column C), and another column where you can paste this monster formula which is everything I explained above in 1 long line:

=C4&(ROUNDUP(((MID(C4,2,1)+MID(C4,4,1)
+MID(C4,6,1)+MID(C4,8,1)+MID(C4,10,1)+MID(C4,12,1))*3)
+(MID(C4,1,1)+MID(C4,3,1)+MID(C4,5,1)+MID(C4,7,1)
+MID(C4,9,1)+MID(C4,11,1)),-1)-(((MID(C4,2,1)+MID(C4,4,1)
+MID(C4,6,1)+MID(C4,8,1)+MID(C4,10,1)+MID(C4,12,1))*3)
+(MID(C4,1,1)+MID(C4,3,1)+MID(C4,5,1)+MID(C4,7,1)
+MID(C4,9,1)+MID(C4,11,1))))

And that’s how I used an Excel formula to generate a 13 digit barcode check digit.

62 Comments

  • peter hayward

    5 June 2011 at 01:43

    4 june 2011

    I would like to thank the person responsible for this article, having read it I now know how to solve at least part of my problem.

    Up to now I have been using a site on the internet to convert my ISBN numbers, which is great but I means I am adding extra work to my data entry, now at lest I can do it in one direction and how knows with a bit more thought maybe in both direction

    Regards Pete

  • 1Earth

    6 June 2011 at 00:28

    You're welcome. It's always a pleasure when my blog posts are useful to others 🙂

  • Luke

    10 June 2011 at 03:47

    Thanks for the article. The formula really works ! Cheers.

  • 1Earth

    10 June 2011 at 05:03

    I would hope so; it generated all the barcodes for the products in the diveshop I used it for. Glad if it helped you too.

  • Thierry

    20 June 2011 at 14:00

    Great stuff this EAN13 generator !!

  • Rob

    22 June 2011 at 05:09

    Great help – thanks!

    I only wanted the check digit so I used the following instead of taking the sum from the roundup figure, which also works.:

    =MOD(((MID(B4,2,1)+MID(B4,4,1)+MID(B4,6,1)

    +MID(B4,8,1)+MID(B4,10,1)+MID(B4,12,1))*3)+(MID(B4,1,1)+MID(B4,3,1)+MID(B4,5,1)

    +MID(B4,7,1)+MID(B4,9,1)+MID(B4,11,1)

    ),10)

  • Shan

    9 September 2011 at 17:10

    Hi,

    Thank you for this article. I am sure I will run into this very soon. I just installed openbravo and trying to figure out how to import data from Excel into the openbravo system. Could you please tell me what to do after creating the excel file like you said above? Thank you.

    Shan.

  • 1Earth

    9 September 2011 at 17:40

    Hi Shan – I did it by importing a .csv file into my database (which on my OpenBravoPOS install is MySQL (OpenBravoPOS using MySQL instructions).

    First I set up the Excel spreadsheet to reflect the table 'products' from the OpenBravoPOS database. I imported all the data about my products this way, but I guess those who know what they're doing (not me) could probably import only the barcodes too.

    Then, once you've created your barcodes, you "Save As…" the Excel spreadsheet as a comma separated values file (.csv). It's that .csv file that you then import into the database.

    Do this on a test database if you're a noob like me. For importing a .csv into MySQL you can find instructions from the MySQL website here.

    I did this a while ago already and unfortunately I didn't save the exact instructions, but I hope this sorts you out.

    If you are working with MySQL I would suggest getting MySQL Workbench – a visual tool which makes working with the database much easier.

  • Mary Fc

    14 September 2011 at 02:02

    Great great great Help!!! Thanks!!! Very good!
    I used openoffice calc. I only have to switch "," to ";" and it worked perfectly.
    Thank you! =)

  • 1Earth

    14 September 2011 at 03:32

    Oh, great! Thanks for the feedback, glad to know it works like that in OpenOffice too.

  • Sourabh

    27 September 2011 at 21:20

    Hey thanks for your help but can you please explain how you can do it in an Excel 2010 sheet as you have explained about re-generating them from your excel sheet into database but i need to generate them in an excel sheet.. Is there any formula or free software available?? please suggest.

    Thanks.

  • 1Earth

    27 September 2011 at 22:08

    Hi, I don't understand what you mean. This formula is exactly for generating it in an Excel spreadsheet. Wether or not you import into a database is irrelevant, the article above describes the formula for generating the code in Excel.

  • Auris

    11 November 2011 at 07:27

    Thanks, that was a great help!

  • ankan

    23 November 2011 at 22:30

    thanx:)

    worked fine in Excel 2002 (2000), after I translated into swedish (MID to EXTEXT, and ROUNDUP to AVRUNDA.UPPÅT) and turned the (,) to (;)

  • Davi Chiang

    30 November 2011 at 23:25

    OUTSTANDING!!!
    Worked perfectly for what I needed. THX A LOT!

  • alicia

    4 January 2012 at 08:38

    How is it different for a 7 digit id number? I'm totally clueless on all this stuff.

  • 1Earth

    12 January 2012 at 09:52

    Not sure about 7 digits, but there is probably some other formula for generating its check digit. Google is your friend 🙂

  • POS

    19 February 2012 at 11:04

    Thanks a LOT.

  • gigoodall

    10 June 2012 at 00:20

    Take you for taking the time out to provide this information. Saved me tons of time….

  • jaber

    28 June 2012 at 16:19

    thanks for lot of information

    i have a shop and i need to switch to open bravo pos so i need to store all product barcode in it, can you guide me to do it one time becouse its hard to store product one by one and also i dont have experience in MySQL.

  • steve wise

    30 July 2012 at 19:18

    I think I saved a few parentheses with this where D4 is the barcode less check digit:

    =D4&10-MOD(3*(MID(D4,2,1)+MID(D4,4,1)+MID(D4,6,1)+MID(D4,8,1)+MID(D4,10,1)+MID(D4,12,1))+(MID(D4,1,1)+MID(D4,3,1)+MID(D4,5,1)+MID(D4,7,1)+MID(D4,9,1)+MID(D4,11,1)),10)

    Steve

  • Mamoun Zater

    31 August 2012 at 19:39

    Thank you ,you have just very big issue for me!!

  • alan

    24 September 2012 at 18:46

    Thank you…for the big help.

  • Aleš

    31 January 2013 at 10:33

    I'm sending you a sunny greetings from Slovenia!
    You saved me from a lot of thinking, calculating,…

    Thank you for this help with formula!

    Aleš

  • 1Earth

    4 February 2013 at 09:37

    Glad I could help, although never stop thinking 🙂

  • Ann Karina Robson

    31 May 2013 at 21:47

    I am trying to use your formula, but I just get an error saying it is not working. I have translated the formula names into Danish as I am using a Danish version of Excel. I have your example 123456789012 in column C in row 4 and then I place the cursor in column D in row 4. After this, I paste the formular at the top and get the error saying that the formula is not working. It highlights this: C4,2,1

    Can you explain it for dummies? 🙂

  • Kerrie

    3 June 2013 at 09:31

    What would the formula be for EAN-8 barcodes? I have 7 digit student numbers and need to calculate the 8th digit for the student barcodes… I'm not familiar enough with it to convert the above formula to EAN-8. Can you help?

  • valentijn

    11 June 2013 at 11:55

    Thank you so much, i translated this formula to dutch and it worked perfectly,
    you saved me so much time and errors,

    Best wishes from Belgium

  • 1Earth

    21 June 2013 at 22:06

    Hi Kerrie

    EAN 8 apparently is similar, but slightly different – here's how that formula works, hope you can make something of it: http://barcode-coder.com/en/ean-8-specification-1….

  • 1Earth

    21 June 2013 at 22:13

    Hi Ann, what you did sounds like it should have worked – I followed your instructions to see if I could recreate the error, but it worked 🙂

    Here's a link to Danish & English translations of Excel functions http://hi.au.dk/uploads/File/kurser/excel/excel-f

    MID becomes MIDT and ROUNUP becomes RUND.OP

    Hope you can make it work.

  • 1Earth

    21 June 2013 at 22:16

    Glad it helped 🙂

  • 1Earth

    21 June 2013 at 22:38

    Ok, it works exactly like the EAN-13 – so here's the formula, edited to work with the EAN-8:

    =C4&(ROUNDUP(((MID(C4,1,1)+MID(C4,3,1)
    +MID(C4,5,1)+MID(C4,7,1))*3)
    +(MID(C4,2,1)+MID(C4,4,1)+MID(C4,6,1)),-1)-(((MID(C4,1,1)+MID(C4,3,1)
    +MID(C4,5,1)+MID(C4,7,1))*3)
    +(MID(C4,2,1)+MID(C4,4,1)+MID(C4,6,1))))

  • Lana

    20 August 2013 at 09:02

    1Earth I want to kiss you, you are sooo AWESOME!!! Thank you so very much.

    I’d been gooling everything from Excel Formula to make a barcode text to simple excel barcode generator and after 50 useless pages I found this one and it is easy peasy! Thank you so much. I’m so glad I didn’t have to download a program and it just worked beautifully.

    Thank you so much!!!

  • 1Earth

    25 August 2013 at 01:32

    Yes, kisses is a perfectly acceptable form of compensation 🙂 Glad it helped you out.

  • Bareyal

    7 October 2013 at 13:22

    1Earth – you saved me a bunch of time. Simple and easy. this is the way !!!

  • Webmaster

    31 October 2013 at 19:28

    Thank you. I just replaced the , to ; and it helped me a lot on creating an EAN13 validation field.

  • Martin

    5 November 2013 at 12:41

    Thanx for the help. Really useful. It works great in Excel 2013. Just change “,” for “;” and “C4” for “$C4”. and from here just copy and paste.

  • ddarko75@rocketmail.com

    5 November 2013 at 15:47

    That doesn’t work correctly, as if the reslut of the ‘MOD…’ part of the equation is ‘0’ then the formula adds ’10’ to the end of the barcode.

  • Jackson

    2 May 2014 at 04:16

    This is a total life saver! I was manually entering the codes for the 13th check digit. This formula rocks!!!
    I copied and pasted the formula on Word and used FIND to replace C4 with my desired Excel Cell. Wahla! A whole column of 13th check digit created in seconds. Love you!

  • Asim

    5 May 2014 at 15:55

    i have to say this is an excellent explanation and massive help thanks 😀

  • BN

    1 June 2014 at 04:29

    thank you !

  • Lila

    7 November 2014 at 14:36

    Thank you very much for this post, especially for tanking the care of explaining each part. This was really useful for me since I use libre office calc in Italian, so I had to transform and TRANSLATE the functions! Here is my final formula
    =C4&(ARROTONDA.ECCESSO(((STRINGA.ESTRAI(C4;2;1)+STRINGA.ESTRAI(C4;4;1)+
    STRINGA.ESTRAI(C4;6;1)+STRINGA.ESTRAI(C4;8;1)+STRINGA.ESTRAI(C4;10;1)+
    STRINGA.ESTRAI(C4;12;1))*3)+(STRINGA.ESTRAI(C4;1;1)+STRINGA.ESTRAI(C4;3;1)+
    STRINGA.ESTRAI(C4;5;1)+STRINGA.ESTRAI(C4;7;1)+STRINGA.ESTRAI(C4;9;1)+
    STRINGA.ESTRAI(C4;11;1));10)-(((STRINGA.ESTRAI(C4;2;1)+
    STRINGA.ESTRAI(C4;4;1)+STRINGA.ESTRAI(C4;6;1)+STRINGA.ESTRAI(C4;8;1)+
    STRINGA.ESTRAI(C4;10;1)+STRINGA.ESTRAI(C4;12;1))*3)+(STRINGA.ESTRAI(C4;1;1)+
    STRINGA.ESTRAI(C4;3;1)+STRINGA.ESTRAI(C4;5;1)+STRINGA.ESTRAI(C4;7;1)+
    STRINGA.ESTRAI(C4;9;1)+STRINGA.ESTRAI(C4;11;1))))

  • Drew Miller

    15 November 2014 at 01:05

    Thanks for this. I implemented it and it works great… but for my project I need to calculate the check digit for UPC-A (12-digit) barcodes given the first 11 digits.

    Do I just edit your formula to eliminate references to MID(C4,12,1)?

  • Jaco Swanepoel

    26 November 2014 at 12:04

    The UPC-A is similar, but a wee bit different. For one, the first part of the formula starts with the digit in position 1, where EAN-13 stars with the digit in position 2. So you will have to change the even numbers in MID() to odd numbers, ie. MID(C4,2,1) to MID(C4,1,1). This WIKIPEDIA page explains it further with an example. Not sure of the last operation is a shortcut to what I did, but try it out with their example and see if it works.

  • CheekyBiscuit

    8 December 2014 at 01:33

    Thank you SOOO much for sharing this, I really needed this for work as I was struggling to find out how check no. was determined. You’re my excel hero! 🙂

  • Paresh

    20 February 2015 at 09:12

    Great Work Buddy have eased out my Tensions to great Extent Cheers !!!!

  • Jorps

    2 March 2015 at 21:37

    Thanks, this was very helpful and saved me a lot of time!

  • Michael M

    17 April 2015 at 19:27

    The way I do it is here:

    =CONCATENATE(A16,IF(MOD(3*(MID(A16,1,1)+MID(A16,3,1)+MID(A16,5,1)+MID(A16,7,1)+MID(A16,9,1)+MID(A16,11,1))+MID(A16,2,1)+MID(A16,4,1)+MID(A16,6,1)+MID(A16,8,1)+MID(A16,10,1),10)=0,0,10-MOD(3*(MID(A16,1,1)+MID(A16,3,1)+MID(A16,5,1)+MID(A16,7,1)+MID(A16,9,1)+MID(A16,11,1))+MID(A16,2,1)+MID(A16,4,1)+MID(A16,6,1)+MID(A16,8,1)+MID(A16,10,1),10)))

    And if I don’t want to see the N/A

  • K

    19 May 2015 at 22:23

    Thanks! Helped a lot

  • Rob

    26 May 2015 at 07:50

    Thank you!
    Thank you!!
    Thank you!!!
    From South Florida USA 🙂

  • Carlos Teixeira

    1 June 2015 at 20:05

    This approach only works if my first digit (from left to right) is different than zero, otherwise I get #VALUE as result. Did anyone have the same issue?

  • Xavi

    2 October 2015 at 00:27

    Thank you!!!!

  • Amir

    20 January 2016 at 06:22

    In case anyone was wondering for UPC-A check digit formula

    =10-MOD((SUM(MID(I3,1,1)+MID(I3,3,1)+MID(I3,5,1)+MID(I3,7,1)+MID(I3,9,1)+MID(I3,11,1))*3)+SUM(MID(I3,2,1)+MID(I3,4,1)+MID(I3,6,1)+MID(I3,8,1)+MID(I3,10,1)),10)

  • Ran

    10 February 2016 at 18:32

    Hi Luke, Thanks for the article. Do you know to do this in Access 2013?

  • Ran

    10 February 2016 at 18:34

    Sorry for the missing word on my previous question, I meant Do you know how to do this Excel formula in MS Access 2013?

  • Grant

    1 August 2016 at 09:40

    If only I’d seen this before I had gone through a lengthy process of developing my own Excel check digit calculation (mine works, but is nowhere near as elegant)

    But just to complicate things, I also need to find a formula for the price validation digit (I am working with EAN13 barcodes that have 4-digit price immediately before the check digit, and the digit before the price is evidently a price validation somehow calculated from the price)

    🙁 Lengthy google searches have thus far failed to identify any formula that consistently generates the same result as the barcode printer I am attempting to program a replacement for…

  • Yaku

    1 August 2016 at 10:37

    Hi Grant,

    I’m intrigued. Can you post 3 or 5 samples of your prices and the corresponding barcodes it created? Might be an interesting puzzle challenge.

  • Sylvain

    21 August 2016 at 23:34

    OK thanks a lot too. Here is fhe French version of it :
    =C4&(ARRONDI.SUP(((STXT(C4;2;1)+STXT(C4;4;1)+STXT(C4;6;1)+STXT(C4;8;1)+STXT(C4;10;1)+STXT(C4;12;1))*3)+(STXT(C4;1;1)+STXT(C4;3;1)+STXT(C4;5;1)+STXT(C4;7;1)+STXT(C4;9;1)+STXT(C4;11;1));-1)-(((STXT(C4;2;1)+STXT(C4;4;1)+STXT(C4;6;1)+STXT(C4;8;1)+STXT(C4;10;1)+STXT(C4;12;1))*3)+(STXT(C4;1;1)+STXT(C4;3;1)+STXT(C4;5;1)+STXT(C4;7;1)+STXT(C4;9;1)+STXT(C4;11;1))))

  • Peter

    29 November 2016 at 04:40

    I have a large list of complete EAN 13 numbers (thus numbers of 13 digits) in column A and I like to take away the check digit so that the remaining 12 digits are listed in column B.

    With what formula can I achieved that?

  • Yaku

    29 November 2016 at 07:05

    Hi Peter, in PHP it’s called substring, in Excel you can use LEFT(A1, 12) in column B for instance. It means from the left in cell A1, show the first 12 characters.

  • valeri kovtoen

    18 April 2017 at 01:32

    Is there a way to generate EAN-14 from a EAN 13 number?

    Or at least a EAN 14 generation would help a lot already

  • Daniel Lewis

    9 May 2017 at 22:39

    Thank you, thank you, thank you!!! you saved me hours of work… Legend

Post a Comment

%d bloggers like this: