+ Reply to Thread
Results 1 to 7 of 7

Formula for calculating a barcode check digit

  1. #1
    Registered User
    Join Date
    12-03-2007
    Location
    Singapore
    MS-Off Ver
    Professional Plus 2010
    Posts
    42

    Formula for calculating a barcode check digit

    I'm trying to write a formula for calculating the check digit for S10 (UPU Standard) barcodes of the Universal Postal Union. Here's an example of a barcode:

    barcode217794027.jpg

    These barcodes incorporate a 9 digit number, with the right-most digit being the check-digit, which is calculated as follows:

    ---

    1. Assign the weights 8, 6, 4, 2, 3, 5, 9, 7 to the 8 digits, from left to right

    2. Calculate S, the sum of each digit multiplied by its weight.
    For example, for the number 21779402, S = 2*8 + 1*6 + 7*4 + 7*2 + 9*3 + 4*5 + 0*9 + 2*7 = 125

    3. Calculate the check digit, C, from C = 11 - (S mod 11) = 11 - (125 mod 11) = 11 - 4 = 7
    If C = 10, change to C = 0
    If C = 11, change to C = 5

    Answer: check digit is 7

    ---

    With my 8 digit number in cell A1, I use this formula in B1 to find the check digit:

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

    However, when the first digit of the barcode is zero, I get #VALUE! error. How can I fix that.

    Also, I am trying to deal with C = 10 and C = 11 with a formula in cell C1: IF(B1=10,0,B1) IF(B1=11,5,B1) How can I combine these two formulas?

  2. #2
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,911

    Re: Formula for calculating a barcode check digit

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  3. #3
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,911

    Re: Formula for calculating a barcode check digit

    Try below formula

    =11-(mod(sum(mid(text(a1,"00000000"),{1,2,3,4,5,6,7,8},1)*{8,6,4,2,3,5,9,7}),11))
    OR Can try direct formula
    =LOOKUP(11-(MOD(SUM(MID(TEXT(A1,"00000000"),{1,2,3,4,5,6,7,8},1)*{8,6,4,2,3,5,9,7}),11)),{1,2,3,4,5,6,7,8,9,10,11},{1,2,3,4,5,6,7,8,9,0,5})
    Last edited by samba_ravi; 06-28-2019 at 06:36 AM.

  4. #4
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Formula for calculating a barcode check digit

    Please key at A1 all 9 digit 217794027

    Then
    B1 =11-MOD(SUMPRODUCT(MID(TEXT(A1,REPT(0,9)),ROW($A$1:$A$8),1)*{8;6;4;2;3;5;9;7}),11)

    For 3. C =10 to 0 and 11 to 5
    C1
    =IFERROR(MOD(1/(1/MOD(11-MOD(SUMPRODUCT(MID(TEXT(A1,REPT(0,9)),ROW($A$1:$A$8),1)*{8;6;4;2;3;5;9;7}),11),11)),10),5)

  5. #5
    Registered User
    Join Date
    12-03-2007
    Location
    Singapore
    MS-Off Ver
    Professional Plus 2010
    Posts
    42

    Re: Formula for calculating a barcode check digit

    Quote Originally Posted by samba_ravi View Post
    =LOOKUP(11-(MOD(SUM(MID(TEXT(A1,"00000000"),{1,2,3,4,5,6,7,8},1)*{8,6,4,2,3,5,9,7}),11)),{1,2,3,4,5,6,7,8,9,10,11},{1,2,3,4,5,6,7,8,9,0,5})
    Your direct formula works perfectly. Thank you.

  6. #6
    Registered User
    Join Date
    04-30-2020
    Location
    morocco
    MS-Off Ver
    2016
    Posts
    1

    Re: Formula for calculating a barcode check digit

    Hi I have the same problem I tested the formulas its not working for me, someone can help me??

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,524

    Re: Formula for calculating a barcode check digit

    Administrative Note:

    Hello abdelhak and Welcome to Excel Forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Bank Recon - How to convert 8 digit formatted check numbers to 6 digit
    By Quisp in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-21-2017, 09:55 PM
  2. Barcode Check Digit Calaculation
    By ALC1167 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-24-2017, 01:59 PM
  3. [SOLVED] Calculate check digit forEAN-8 barcode
    By yanceygm in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-19-2016, 12:16 AM
  4. Barcode Check Digit Formula
    By strud in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-16-2013, 10:12 AM
  5. Mod 11 - Check Digit Barcode
    By pr4t3ek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2011, 04:30 AM
  6. Macro to force format and check barcode check digit
    By Code Flunkie in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-02-2009, 10:27 AM
  7. GTIN Barcode Check Digit Help
    By brohlfs in forum Excel General
    Replies: 7
    Last Post: 05-15-2009, 11:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1