+ Reply to Thread
Results 1 to 29 of 29

how do I take a two digit number, separate the two digits, add them together, show result

Hybrid View

  1. #1
    Registered User
    Join Date
    04-07-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    8

    how do I take a two digit number, separate the two digits, add them together, show result

    I am trying to create a small sheet that applies an algorithm to a nine digit barcode number to calculate the check digit which becomes the 10th.

    Attached is the spreadsheet. With the logic of the algorithm included in it.

    I've created the method of applying the multiplier to the individual digits of the barcode (In Row 6)

    The result of each calculation is in Row 7.

    The difficulty is that if the result is a number greater than 9, (in other words two digits) then the number needs to be split - e.g. 14 becomes 1+4 or 18 becomes 1+8, with the sum being the number displayed.

    I hope that makes sense - the algorithm is explained in the spreadsheet attached.

    I think something like IF result is < 9 , then subtract 10 and add 1 might do it....? But I don't know how to structure that in the cell.

    Any help appreciated!

    Greg
    Attached Files Attached Files
    Last edited by FDibbins; 04-07-2013 at 08:17 PM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Is this calculation possible??

    Hi and welcome to the forum

    We would love to help you with your question, but 1st, in accordance with forum rules, please rename your thread to something more meaningful, that actually describes your problem.

    Because thread titles are used in searching the forum it is vital they be written to accurately describe your thread content or overall objective using ONLY search friendly key words. That is, your title used as search terms would return relevant results.

    Also, many members will look at a thread title, and if it is of interest to them, or it falls within their area of expertese, they might only open those threads.

    Look at it this way...if you typed that title into google, what would you expect to get back?
    To change a Title on your post, click EDIT on you're 1st post, then Go Advanced and change your title
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    04-07-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    8

    Smile Re: Is this calculation possible??

    [QUOTE=FDibbins;3187974]Hi and welcome to the forum

    We would love to help you with your question, but 1st, in accordance with forum rules, please rename your thread to something more meaningful, that actually describes your problem.




    I'd like to oblige, but am struggling to think of how to describe it in a succinct phrase!

    I'd have thought a question like 'is this calculation possible.' would grab the interest of anyone with a curiosity and an inveterate knowledge of Excel..!

    The question really is ' how do I take a two digit number, separate the two digits, add them together and display the result?' isn't that a bit long for a thread title?

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: how do I take a two digit number, separate the two digits, add them together and displ

    Nope, doesnt seem too long to me?

  5. #5
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    I´m sure there will be a more elegant way to do this but try this on cell C7 and drag across.

    =IF(C5*C6>9;LEFT(C5*C6;1)+RIGHT(C5*C6;1);C5*C6)
    If you found the solution to your question. Mark the thread as "Solved"
    Thank everyone that helped you with a valid solution by clicking on their

    There is no such thing as a problem, only a temporary lack of a solution

  6. #6
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    And for the other formula in L7, see if it works. (For sure a simpler way to get this is available)

    =IF(SUM(C7:K7)/10-TRUNC(SUM(C7:K7)/10)=0;0;10-RIGHT(SUM(C7:K7)/10-TRUNC(SUM(C7:K7)/10)))

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Try this where C5:K5 is your bar code digits and C6:K6 your algorithm
    Formula: copy to clipboard
    =SUM(INDEX(INT(INDEX(C5:K5*C6:K6,,)/10)+(MOD(INDEX(C5:K5*C6:K6,,),10)),,))

    [EDIT]
    Rearranged your sample workbook, and made the formula dragable See the attached.
    Attached Files Attached Files
    Last edited by Marcol; 04-08-2013 at 05:11 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Assuming your alogrithm is constant, you might want to go this way
    Formula: copy to clipboard
    =SUM(INDEX(INT(INDEX(C2:K2*{2,1,2,1,2,1,2,1,2},,)/10)+(MOD(INDEX(C2:K2*{2,1,2,1,2,1,2,1,2},,),10)),,))

    See the attached.
    Attached Files Attached Files

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    simple method
    C7: =SUM(--(MID(C5*C6&"0",{1,2},1)))
    copy across.
    L7: =MOD(10-MOD(SUM(C7:K7),10),10)

    or if you just want one cell without the intermediate steps:
    L7: =MOD(10-MOD(SUM(--MID((C5:K5*{2,1,2,1,2,1,2,1,2})&"0",{1;2},1)),10),10)
    array-entered

    there are surely more elegant ways ;-)
    Last edited by JosephP; 04-08-2013 at 05:48 AM.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  10. #10
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Quote Originally Posted by JosephP View Post
    L7: =MOD(10-MOD(SUM(C7:K7),10),10)
    Cool, for a minute, I thought I read the question wrong. This is a Monica Bellucci formula

    Quote Originally Posted by JosephP View Post
    or if you just want one cell without the intermediate steps:
    L7: =MOD(10-MOD(SUM(--MID((C5:K5*{2,1,2,1,2,1,2,1,2})&"0",{1;2},1)),10),10)
    array-entered
    I got an error with this one. Entered array, I´m sure it was lost in translation from English to Portuguese syntax.
    If it does what it says on the tin, this is a Audrey Hepburn one!

  11. #11
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Quote Originally Posted by JosephP View Post
    ... if you just want one cell without the intermediate steps:
    L7: =MOD(10-MOD(SUM(--MID((C5:K5*{2,1,2,1,2,1,2,1,2})&"0",{1;2},1)),10),10)
    array-entered
    Are we reading this differently?
    I make the answer 21 not 9
    i.e. Sum the digits in the result row.

  12. #12
    Registered User
    Join Date
    04-07-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Quote Originally Posted by JosephP View Post
    simple method
    C7: =SUM(--(MID(C5*C6&"0",{1,2},1)))
    copy across.
    L7: =MOD(10-MOD(SUM(C7:K7),10),10)

    or if you just want one cell without the intermediate steps:
    L7: =MOD(10-MOD(SUM(--MID((C5:K5*{2,1,2,1,2,1,2,1,2})&"0",{1;2},1)),10),10)
    array-entered

    there are surely more elegant ways ;-)
    Hi

    I can't decipher what the formula is doing (that's my failing!) But putting it into a Spreadsheet I can't get it to calculate across. Probably me being dense - can you put it into a spreadsheet and attach it for me, please?? Maybe it'll make sense if I can see that the check digit is calculating correctly versus my manual calculations...
    Thanks

    Greg

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    the instructions in the sample imply the final answer is 9 I reckon

  14. #14
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    I read 9 also, he´s looking for the 10th digit

  15. #15
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Joseph, could you attach the array formula in a sheet please? My OCD is not letting this go away

    There is Brazilian Portuguese and European Portuguese formula names and it seems none work.

    I found that sometimes, the sheet I use for getting English to Portuguese formulas is not properly updated so I would like to know which is the proper one so I can update it with the right answer for this syntax.

  16. #16
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    yes sure thing
    Attached Files Attached Files

  17. #17
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Thanks, my issue was here.

    {2,1,2,1,2,1,2,1,2} I had to change the "," to "."
    I had it changed before from "," to ";"

    Nice one

  18. #18
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,697

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    You could also use this "non-array" version......

    =MOD(SUMPRODUCT(-MID(C5:K5*{2,1,2,1,2,1,2,1,2}&0,{1;2},1)),10)
    Audere est facere

  19. #19
    Registered User
    Join Date
    04-07-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    8

    Thumbs down Re: how do I take a two digit number, separate the two digits, add them together, show res

    Quote Originally Posted by daddylonglegs View Post
    You could also use this "non-array" version......

    =MOD(SUMPRODUCT(-MID(C5:K5*{2,1,2,1,2,1,2,1,2}&0,{1;2},1)),10)

    Thanks for the suggestion, fellow Spur, but it doesn't calculate correctly.

    Your formula delivers the result of 5 for the check digit, on this sequence:

    0 4 12 2 4 5 6 3 2 5


    but manually I make the check digit 0. 0+4+1+2+2+4+5+6+3+2= 29 , so 29 divided by 10 = 2.9 . Subtract the remainder (9) from 10 = 1, therefore the check digit is 1 (or should be)


    Greg

  20. #20
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,697

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Quote Originally Posted by GregInLondon View Post
    Your formula delivers the result of 5 for the check digit, on this sequence:

    0 4 12 2 4 5 6 3 2 5
    Hello Greg,

    I think we are starting from different places, that list, 0,4,12,2,4,5,6,3,2 appears to be the numbers after multiplication by 2,1,2 etc.....

    My suggested formula works on the original data labelled "number" in row 5, so from the above list I deduce that the numbers in row 5 are

    0,4,6,2,2,5,3,3,1

    If those are the contents of C5:K5 then my suggested formula does the whole calculation, multiplies those numbers by 2,1,2,1,2,1,2,1,2, sums all the digits (to get 29) and then calculates the "reverse remainder" to give 1 as the result as you say. Joseph's long formula in post 9 should give the same results

  21. #21
    Registered User
    Join Date
    04-07-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    OPC Code Algorythm DaddyLonglegs.xlsx

    Hi

    I'm sorry, I am probably being really thick. Can I ask you to do me a further favour - I've attached a spreadsheet (OPC Code Algorythm DaddyLonglegs.xlsx ) with a model that shows three different products and their barcode numbers (at least, the first 9 digits)

    I've manually calculated (simple formula of multiplying the barcode digits alternately by 2 or 1) the algorithm across for the first nine numbers in columns D through to L, then in column M I've entered what I think the check digit should be. Could you put your formula into the third row in each example and calculate the check digit with your formula into Column M. Then I HOPE either the penny will drop in my befuddled brain or I'll just be able to do a few tests to check your calculations against real, checked barcode numbers and just be able to rest easy knowing it works!

    Thanks for your patience... I thought I was about a blue belt with Excel, but I am feeling little more than a yellow, at best...

    Thanks!!!
    Attached Files Attached Files

  22. #22
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Okay
    Silly me, somehow I managed to miss this bit ...
    Divide the result by 10; in this example, 21 divided by 10 = 2 with a remainder of 1. Subtract the remainder from 10 to obtain the check digit; in this case, 10 - 1 = 9. If the result is 10 (in the case of 10 - 0 = 10) change the result to 0.

  23. #23
    Registered User
    Join Date
    04-07-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Everyone - apologies for going quiet since you all flexed your grey matter on this. Not forgotten, still needed, but I have been snowed under on other things.

    I am going to take a look at the suggestions tomorrow and see what I have from you.

    Stay tuned...!

    Greg

  24. #24
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    I already did in post 15 ;-)

  25. #25
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,697

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Here's a sample with some randomly generated numbers (press F9 to re-generate) and with the results for my suggested formula and JP's in columns M and N - you can see that the results are the same.

    Joseph's formula needs to be array entered. Put the formula in a cell, press F2 key to select formula then hold down CTRL and SHIFT keys while pressing ENTER. If done correctly the formula is automatically surrounded by curly braces like { and }
    Attached Files Attached Files

  26. #26
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,697

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Hello Greg,

    My suggestion doesn't calculate intermediate results. If you have your 9 barcode digits in D4:L4 then the formula calculates the final check digit directly from those cells, so if you use

    =MOD(SUMPRODUCT(-MID(D4:L4*{2,1,2,1,2,1,2,1,2}&0,{1;2},1)),10)

    That gives you the check digit (5 in your example) with a single formula.

    See attached - I put that formula in N5 and copied to N9 and N13 for the other two examples. The first two match your results - I make the third check digit 4 not 5 (don't forget that 10 = 1+0 =1)

    If you want to break it down more then try Joseph's "simple method" in post #9
    Attached Files Attached Files
    Last edited by daddylonglegs; 04-19-2013 at 05:10 AM.

  27. #27
    Registered User
    Join Date
    04-07-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    Fabulous! That's done it. Really appreciate your assistance and patience. I tested it with a number of items where the barcode was already calculated and it worked each time. I'll look again (with fresh understanding) at Joseph's formula, but I've used yours to make a spreadsheet that will suffice for single or multiple calculations. I'm none the wiser (really) as to how your formula works, but it does - and that's all the matters! :-)

    Thanks again - and Audere est Facere! After today we need to Facere a lot!

    Greg

  28. #28
    Registered User
    Join Date
    09-20-2023
    Location
    OK
    MS-Off Ver
    windows 10
    Posts
    1

    Re: how do I take a two digit number, separate the two digits, add them together, show res

    OMG, I need this information as well. I have a spreadsheet that was created to check scanline and the check digit for a previous place I worked. I am trying to update it with new info and would love to find out if the person that posted this question originally got any help. Thanks so much

  29. #29
    Registered User
    Join Date
    04-07-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    8

    Question Re: how do I take a two digit number, separate the two digits, add them together, show res

    Good Lord.... I was amazed to be reminded of this thread by tkerr's latest. Over ten years on I can't remember why I needed this - I mean what I was doing to require the calculation. All I can suggest is follow daddylonglegs suggestions in the thread> I presume that he may also have an alert that you posted a follow up - I'll see if I can find a copy of he spreadsheet I refer to below. Very doubtful but we'll see.

    Just realised the spreadsheets are downloadable from the thread itself. Just wish I could remember what project or whatever I was working on that caused me to ask in the first place!

    What are you working on tkerr?
    Last edited by GregInLondon; 09-20-2023 at 01:12 PM. Reason: Realised attachments available in thread

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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