Ean 13 расчет excel

February 24 2009, 16:22

Опубликовано на russur.ru — блог про жизнь. Оставить комментарий можно там.

Как известно, в штрихкоде формата EAN-13 13-й символ проверочный, он вычисляется из двенадцати по хитрой формуле. Не напоминает историю с сайлонами из Battlestar Galactic? :)

Дык вот, по работе пришлось соорудить формулу превращающую 12-значный штрихкод в 13-значный. Дело это было оочень непростое :) Путь был тернист: поискал а есть ли такое уже, нашел мегаприблуду на Экселе некоего крутого перца защитившего приблуду паролем. Ну дальше по полной: поиск проги вскрывающей эти пароли, поиск кряка к проге, успешное ломание, переделка — и вот оно, «я взлетаю» © Финам-ФМ:

=[cell]*10+MOD(10-MOD(3*(MID([cell];2;1)+MID([cell];4;1)+MID([cell];6;1)+MID([cell];8;1)+MID([cell];10;1)+MID([cell];12;1))+MID([cell];1;1)+MID([cell];3;1)+MID([cell];5;1)+MID([cell];7;1)+MID([cell];9;1)+MID([cell];11;1);10);10)

В формуле, понятное дело, [cell] означает ячейку в которой 12-значный штрихкод.

Как известно, в штрихкоде формата EAN-13 13-й символ проверочный, он вычисляется из двенадцати по хитрой формуле. Не напоминает историю с сайлонами из Battlestar Galactic? icon_smile.gif

Дык вот, по работе пришлось соорудить формулу превращающую 12-значный штрихкод в 13-значный. Дело это было оочень непростое icon_smile.gif Путь был тернист: поискал а есть ли такое уже, нашел мегаприблуду на Экселе некоего крутого перца защитившего приблуду паролем. Ну дальше по полной: поиск проги вскрывающей эти пароли, поиск кряка к проге, успешное ломание, переделка — и вот оно, «я взлетаю» © Финам-ФМ:

=[cell]*10+MOD(10-MOD(3*(MID([cell];2;1)+MID([cell];4;1)+MID([cell];6;1)+MID([cell];8;1)+MID([cell

];10;1)+MID([cell];12;1))+MID([cell];1;1)+MID([cell];3;1)+MID([cell];5;1)+MID([ce

ll];7;1)+MID([cell];9;1)+MID([cell];11;1);10);10)

В формуле, понятное дело, [cell] означает ячейку в которой 12-значный штрихкод.

Читать на russur.ru

I was preparing data in an Excel spreadsheet for import into an OpenBravoPOS database, and needed to generate check digits for my custom EAN-13 barcodes. 

Here’s the Excel formula I constructed to generate a 13-digit barcode check digit. It works in Google Sheets too!

Click here to skip to straight to the final, monster all-in-one formula, or keep reading to see the how-and-why of the formula’s components.

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 workaround 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. Manufacturers 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 ready-to-print EAN-13 barcode image.

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

  • Starting with,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 / Google Sheets use the MID() function to select the specific digits. If your 12 digit number is in cell C4 (column C row 4) you can add the following to any other cell to see the result:
  • =MID(C4, 2, 1)
  • It takes the 2 as the digit position you want, and the 1 indicates how many digits starting from that position 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 / Google Sheets 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 am I missing something, or is that pointless? So I ignore the * 1 bit in my example:
  • 1 + 3 + 5 + 7 + 9 + 1 = 26
  • In Excel / Google Sheets, use the same MID() function to select these digits. This part of the calculation’s Excel / Google Sheets formula looks like so:
  • =MID(C4,1,1)+MID(C4,3,1)+MID(C4,5,1)+MID(C4,7,1)+MID(C4,9,1)+MID(C4,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 (assuming you pasted the first formula in C5 and the second one in C6).
  • Next, round the result up to the nearest 10. Our example’s result of rounding up from 92 is 100; In Excel / Google Sheets 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 like so:
  • =ROUNDUP(G4,-1)
  • where G4 is the cell location of our un-rounded sum (92), and -1 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
  • Thus, our 13th and check digit for this fictitious barcode is 8. Lastly, automatically add (aka concatenate) your check digit with your 12 digit number with the Excel / Google Sheets 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 added at the end of your 12 digit string: 1234567890128.

The Monster all-in-one Excel Formula

If you want minimal columns in your Excel / Google Sheets 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.

Over the years many others, who found this page looking for this solution, have contributed solutions of their own. The modified formulas below are mostly translationsions into other languages, or tweaked for specific requirements. Have a look:

Contributions from the Comments

Here are some useful varitions on the above that commenters contributed in the comments over the years since this article was originally published:

Ankan’s Swedish Translations:

To get in working in Swedish Ankan suggested the following modifactions (changing the , to ; might have been specific to their setup):

=C4&(AVRUNDA.UPPÅT(((EXTEXT(C4;2;1)+EXTEXT(C4;4;1)+EXTEXT(C4;6;1)+EXTEXT(C4;8;1)+EXTEXT(C4;10;1)+EXTEXT(C4;12;1))3)+(EXTEXT(C4;1;1)+EXTEXT(C4;3;1)+EXTEXT(C4;5;1)+EXTEXT(C4;7;1)+EXTEXT(C4;9;1)+EXTEXT(C4;11;1));-1)-(((EXTEXT(C4;2;1)+EXTEXT(C4;4;1)+EXTEXT(C4;6;1)+EXTEXT(C4;8;1)+EXTEXT(C4;10;1)+EXTEXT(C4;12;1))3)+(EXTEXT(C4;1;1)+EXTEXT(C4;3;1)+EXTEXT(C4;5;1)+EXTEXT(C4;7;1)+EXTEXT(C4;9;1)+EXTEXT(C4;11;1))))

Ann Karina Robson‘s Danish Translation:

Ann struggled to get the formula working, but when I recreated her example it apparently worked for me with the following translations to Danish:

=C4&(ROND.OP(((MIDT(C4,2,1)+MIDT(C4,4,1)+MIDT(C4,6,1)+MIDT(C4,8,1)+MIDT(C4,10,1)+MIDT(C4,12,1))3)+(MIDT(C4,1,1)+MIDT(C4,3,1)+MIDT(C4,5,1)+MIDT(C4,7,1)+MIDT(C4,9,1)+MIDT(C4,11,1)),-1)-(((MIDT(C4,2,1)+MIDT(C4,4,1)+MIDT(C4,6,1)+MIDT(C4,8,1)+MIDT(C4,10,1)+MIDT(C4,12,1))3)+(MIDT(C4,1,1)+MIDT(C4,3,1)+MIDT(C4,5,1)+MIDT(C4,7,1)+MIDT(C4,9,1)+MIDT(C4,11,1))))

Sylvian’s French Translation:

=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))))

Ersin Coketin’s Turkish Translation:

=(YUKARIYUVARLA(((PARÇAAL(C557;2;1)+PARÇAAL(C557;4;1)+PARÇAAL(C557;6;1)+PARÇAAL(C557;8;1)+PARÇAAL(C557;10;1)+PARÇAAL(C557;12;1))3)+(PARÇAAL(C557;1;1)+PARÇAAL(C557;3;1)+PARÇAAL(C557;5;1)+PARÇAAL(C557;7;1)+PARÇAAL(C557;9;1)+PARÇAAL(C557;11;1));-1))-(((PARÇAAL(C557;2;1)+PARÇAAL(C557;4;1)+PARÇAAL(C557;6;1)+PARÇAAL(C557;8;1)+PARÇAAL(C557;10;1)+PARÇAAL(C557;12;1))3)+(PARÇAAL(C557;1;1)+PARÇAAL(C557;3;1)+PARÇAAL(C557;5;1)+PARÇAAL(C557;7;1)+PARÇAAL(C557;9;1)+PARÇAAL(C557;11;1)))

Roberto’s Brazilian Portuguese Translation

=A2&(ARREDONDAR.PARA.CIMA(((EXT.TEXTO(A2;2;1)+EXT.TEXTO(A2;4;1)+EXT.TEXTO(A2;6;1)+EXT.TEXTO(A2;8;1)+EXT.TEXTO(A2;10;1)+EXT.TEXTO(A2;12;1))3)+(EXT.TEXTO(A2;1;1)+EXT.TEXTO(A2;3;1)+EXT.TEXTO(A2;5;1)+EXT.TEXTO(A2;7;1)+EXT.TEXTO(A2;9;1)+EXT.TEXTO(A2;11;1));-1)-(((EXT.TEXTO(A2;2;1)+EXT.TEXTO(A2;4;1)+EXT.TEXTO(A2;6;1)+EXT.TEXTO(A2;8;1)+EXT.TEXTO(A2;10;1)+EXT.TEXTO(A2;12;1))3)+(EXT.TEXTO(A2;1;1)+EXT.TEXTO(A2;3;1)+EXT.TEXTO(A2;5;1)+EXT.TEXTO(A2;7;1)+EXT.TEXTO(A2;9;1)+EXT.TEXTO(A2;11;1))))

Nicolás’ Spanish Translation

=C4&(REDONDEAR.MAS(((EXTRAE(C4;2;1)+EXTRAE(C4;4;1)+EXTRAE(C4;6;1)+EXTRAE(C4;8;1)+EXTRAE(C4;10;1)+EXTRAE(C4;12;1))3)+(EXTRAE(C4;1;1)+EXTRAE(C4;3;1)+EXTRAE(C4;5;1)+EXTRAE(C4;7;1)+EXTRAE(C4;9;1)+EXTRAE(C4;11;1));-1)-(((EXTRAE(C4;2;1)+EXTRAE(C4;4;1)+EXTRAE(C4;6;1)+EXTRAE(C4;8;1)+EXTRAE(C4;10;1)+EXTRAE(C4;12;1))3)+(EXTRAE(C4;1;1)+EXTRAE(C4;3;1)+EXTRAE(C4;5;1)+EXTRAE(C4;7;1)+EXTRAE(C4;9;1)+EXTRAE(C4;11;1))))

Lila’s Italian translation for OpenOffice Calc

=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))))

Yaku is a brewer, baker, and semi-retired trouble maker (semi-retired from trouble-making that is). Although he believes anything is possible, he is nevertheless frequently stupefied by his world and the people in it.
View more posts


Понравилась статья? Поделить с друзьями:
  • Ean 13 excel формула
  • Dream theater images and word торрент
  • Each word meaning of name
  • Dream the word перевод
  • Each word has a different sound