+ Reply to Thread
Results 1 to 24 of 24

calculate value based by replacing letters with numbers

  1. #1
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    calculate value based by replacing letters with numbers

    Hello!

    I need to take a long alphanumeric number and assign the letter's predetermined values and based on those values mulitply and divide them out for a final figure. Or would it be easier to within an Excel cell with a formula?

    for example -

    OOLU 708695.


    Each letter of the prefix has its own value:

    A 10 J 20 S 30
    B 12 K 21 T 31
    C 13 L 23 U 32
    D 14 M 24 V 34
    E 15 N 25 W 35
    F 16 O 26 X 36
    G 17 P 27 Y 37
    H 18 Q 28 Z38
    I 19 R 29



    Each figure of the number has its own value.

    1 1
    2 2
    3 3
    4 4
    5 5
    6 6
    7 7
    8 8
    9 9
    0 0



    We know that: Now calculate:


    O=26 26 X 1 = 26
    O=6 26 X 2 = 52
    L=23 23 X 4 = 92
    U=32 32 X 8 = 256
    7=7 X 16 = 112
    0=0 0 X 32 = 0
    8=8 8 X 64 = 512
    6=6 6 X 128 = 768
    9=9 9 X 256 = 2304
    5=5 5 X 512 = 2560

    --------------------------------------------------------------------------------

    Total = 6682


    Now divide this total by 11:
    6682 / 11 = 607.4545


    and take the figures after the decimal
    and multiply it by 11 to get the check digit.
    0.4545 X 11 = 5


    The complete number is:
    OOLU 708695-5

    what do you think?

    thanks!
    Last edited by jbowling; 06-16-2010 at 02:09 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: calculate value based by replacing letters with numbers

    Based on the sample... if you create a table which has:

    Column 1:
    holding the values 0-Z (formatted as text pre entry such that 0-9 are text)

    Column 2:
    associated numeric value

    Then:

    Please Login or Register  to view this content.
    should generate the OOLU 708695-5 result.

    edit: should add E1:F36 in the above is of course my lookup table of 0-Z and associated numeric value
    Last edited by DonkeyOte; 06-16-2010 at 02:59 PM.

  3. #3
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: calculate value based by replacing letters with numbers

    Try

    =SUMPRODUCT(LOOKUP(MID(UPPER(SUBSTITUTE(A2," ","")),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(A2," ","")))),1),
    {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","Vv","W","X","Y","Z"},
    {0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,23,24,25,26,27,28,29,30,31,32,34,35,36,37,38})*
    (2^(ROW(INDIRECT("1:"&LEN(SUBSTITUTE(A2," ",""))))-1)))

  4. #4
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    Thanks guys

    do you think there is anyway we could convert that to VBA? That way I could just install a macro button on my user's spreadsheets so they can calculate that final digit?

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: calculate value based by replacing letters with numbers

    Hello jbowling,

    Here is VBA macro that you can use, as long as the number format remains the same: 4 digits, a space, and 5 digits. This macro is a UDF, so it can be used on a worksheet like a formula.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    Or even better, can i combine =SUMPRODUCT(LOOKUP(MID(UPPER(SUBSTITUTE(A5,"","")),ROW(INDIRECT("1:"&LEN(SUBSTITUTE(A5," ","")))),1),{"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","Vv","W","X","Y","Z"},{0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,23,24,25,26,27,28,29,30,31,32,34,35,36,37,38}) * (2^(ROW(INDIRECT("1:"&LEN(SUBSTITUTE(A5," ",""))))-1)))/11

    with

    =RIGHT(C5,4)*11/10000

    which would give me the number i'm looking for in one cell and i could just hand out the formula instead.

    Thanks!

  7. #7
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    Fantastic!!!

    you folks are the best

    thanks!

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: calculate value based by replacing letters with numbers

    Quote Originally Posted by jbowling View Post
    Or even better, can i combine ... [formula] ... with
    =RIGHT(C5,4)*11/10000

    which would give me the number i'm looking for in one cell and i could just hand out the formula instead.
    Perhaps I'm mistaken but I thought the formula in post # 2 generated the complete string with check digit in place ...

    (if you prefer the use of inline array constants to a basic 2 column table range then substitute appropriately)

  9. #9
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    that is assuming i have 2 columns of data to support it. Best case scenerio is if i have one all encompassing formula I can dish out that can be added to whatever spreadsheet needs it without having to have the extra columns of data hidden away someplace.

    refering to my orignal post Bob Philips excellent formula gets me to the total, but i still have to divide that by 11 and then take the 4 digits after the decimal and multiply them by 11 to get my final number or "check digit"

    don't ask me why, i didn't invent this insane system, but it is industry wide.

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: calculate value based by replacing letters with numbers

    My point was, the formula in post # 2 does what you need - simply substitute references to E1:F36 with the inline array from Bob's formula (the inline array is simply a hard wired alternative to a range)

    Or, if preferred add the parts from post # 2 that are not in Bob's formula.

    In reality the two formulas are pretty much identical in all other respects.

    Post # 2 using inline - below.

    Please Login or Register  to view this content.
    edit: where A1 holds the original alpha numeric code (modify reference as appropriate)
    Last edited by DonkeyOte; 06-16-2010 at 03:55 PM.

  11. #11
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    Sorry i didin't realize what you meant.

    But even doing so I am getting an wrong answer. For OOLU708695 I should get 5 as the answer but that forumla gives me an 8.

    OOLU708695-8

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: calculate value based by replacing letters with numbers

    So the question would then be: is there a space in the alpha numeric or not ?

    Your latest post implies not whereas your first post implies the opposite to be true.

    If there is not (or it varies) then use:

    Please Login or Register  to view this content.
    Edit: the above would only work with XL2007 and beyond I'm afraid given levels of nesting... for versions prior to that it would be best to split the function parts
    (apologies I should have checked on that basis)
    Last edited by DonkeyOte; 06-16-2010 at 04:15 PM.

  13. #13
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: calculate value based by replacing letters with numbers

    or
    Please Login or Register  to view this content.
    in A UDF
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    to be honest i could go either way, if i just give the final digit it can be used as needed but if it is added to the end that info could be recognized as well.
    Last edited by jbowling; 06-16-2010 at 04:18 PM.

  15. #15
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: calculate value based by replacing letters with numbers

    I'm not sure to whom the last post was aimed - I was not talking about the checkdigit.

    Your first post states:

    OOLU 708695

    Your latter post states:

    OOLU708695

    the space has an impact in so far as it generally warrants use of a Substitute which in turn takes you outside permitted levels of nesting (using the INDEX based approach).

    If you want a single cell native function it has a direct impact on the suggested approaches.

    A UDF makes a great deal of sense IMO - the SUMPRODUCT is inefficient not to mention unwieldy.

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: calculate value based by replacing letters with numbers

    ... but it is industry wide.
    Out of curiosity, what industry?
    Entia non sunt multiplicanda sine necessitate

  17. #17
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    Too many emails and posts at the same time.

    The space in the middle is a non factor, it can be there or not it will not affect anything I need it for.

    and we are working Excel 2003 so it looks like i might have to keep this in 2 pieces as far the formula goes.
    Last edited by jbowling; 06-16-2010 at 04:32 PM.

  18. #18
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    Shipping containers, the very last digit is derived from that crazy formula fo reasons unknown to me.

  19. #19
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: calculate value based by replacing letters with numbers

    Quote Originally Posted by jbowling
    The space in the middle is a non factor, it can be there or not it will not affect anything I need it for.

    and we are working Excel 2003 so it looks like i might have to keep this in 2 pieces as far the formula goes.
    If the spaces are never to exist then you can dispense with the SUBSTITUTEs which should in turn remove nesting issues and thereby permit use pre XL2007:

    Please Login or Register  to view this content.
    but I would still opt for UDF...

  20. #20
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    thanks a lot

    this was a huge help!

  21. #21
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: calculate value based by replacing letters with numbers

    =$a$1&"-"&round(mod(sumproduct(search(mid(a1;row(a$1:index(a:a;len(a1)));1);"0123456789a bcdefghijk lmnopqrstu vwxyz")-1;2^(row(a$1:index(a:a;len(a1)))-1))/11;1)*11;0)
    Last edited by snb; 06-16-2010 at 05:30 PM.

  22. #22
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    I'm back again, i found a few situations where the answer is 10 and mathmatically that is correct but i need that 10 to show up as 0.

    DVRU150060-10
    DVRU150060-0

    any ideas?

  23. #23
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: calculate value based by replacing letters with numbers

    Taking off from snb's formula,

    =A1 & "-" & MOD(ROUND(MOD(SUMPRODUCT(FIND(MID(A1, {1,2,3,4,5,6,7,8,9,10}, 1), "0123456789A BCDEFGHIJK LMNOPQRSTU VWXYZ") - 1, 2^{0,1,2,3,4,5,6,7,8,9})/11, 1) * 11, 0), 10)

    EDIT: or

    =A1 & "-" & MOD(MOD(SUMPRODUCT(FIND(MID(A1, {1,2,3,4,5,6,7,8,9,10}, 1), "0123456789A BCDEFGHIJK LMNOPQRSTU VWXYZ") - 1, 2^{0,1,2,3,4,5,6,7,8,9}), 11), 10)


    No embedded spaces
    Last edited by shg; 06-17-2010 at 07:59 AM.

  24. #24
    Registered User
    Join Date
    06-16-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: calculate value based by replacing letters with numbers

    brilliant!

    thanks

+ 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