+ Reply to Thread
Results 1 to 11 of 11

Sum of digits of the numbers ?

  1. #1
    Registered User
    Join Date
    06-02-2012
    Location
    Romania
    MS-Off Ver
    Excel 2010
    Posts
    95

    Sum of digits of the numbers ?

    Let's say we have in excel the following numbers, each one in each own cell:
    23-18-9-33-92-37

    The goal is to sum all of the digits of all these 6 numbers.
    23=2+3
    18=1+8
    9=9 or 0+9
    33=3+3
    92=9+2
    37=3+7
    And the final result should be:
    2+3+1+8+0+9+3+3+9+2+3+7= 50

    How you do that ?

    Thank you !

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,655

    Re: Sum of digits of the numbers ?

    Let say your numbers are in A1 to F1 try:

    =SUMPRODUCT(--RIGHT(ROUNDDOWN($A1:$F1,ROW($A$1:$A$10)-10)/10^(11-ROW($A$1:$A$10)),1))

    Edit: It return wrong result if has rounded numbers (10,20,30...).
    But since martindwilson formula works fine I won't fix this.
    Last edited by zbor; 06-24-2012 at 04:50 AM.

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sum of digits of the numbers ?

    with the numbers in a1:f1
    =SUM(VALUE(MID(A1&B1&C1&D1&E1&F1,ROW(A1:OFFSET(A1,LEN(A1&B1&C1&D1&E1&F1)-1,0)),1)))
    array entered gives 50
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    06-02-2012
    Location
    Romania
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Sum of digits of the numbers ?

    Thank you o much everyone !

  5. #5
    Registered User
    Join Date
    06-02-2012
    Location
    Romania
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Sum of digits of the numbers ?

    Sorry for reopening this thread again but I tried both formulas and none of them is working.
    I put the file as attachment too.

    Any help, please ?

    Thank you !
    Attached Files Attached Files

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,655

    Re: Sum of digits of the numbers ?

    Of course it doesn't work for first row where you don't have numbers?!
    But for rest of them works:

    =SUM(VALUE(MID(A2&B2&C2&D2&E2&F2,ROW(A$1:OFFSET(A$1,LEN(A2&B2&C2&D2&E2&F2)-1,0)),1)))

  7. #7
    Registered User
    Join Date
    06-02-2012
    Location
    Romania
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Sum of digits of the numbers ?

    Look, I have used this formula and for the first draw it shows to me only 5 while the sum of digits of all 6 numbers is 45 and not 5. Check it out, please. It is as attachment.
    Any help, please ?

    Thank you !
    Attached Files Attached Files

  8. #8
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,655

    Re: Sum of digits of the numbers ?

    COmfirm formula with ctrl+shift+enter (and not just enter)

  9. #9
    Registered User
    Join Date
    06-02-2012
    Location
    Romania
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Sum of digits of the numbers ?

    Quote Originally Posted by zbor View Post
    COmfirm formula with ctrl+shift+enter (and not just enter)
    Ohh, damn, it works man ! I love you ! Thank you ! :D

  10. #10
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Sum of digits of the numbers ?

    there is a problem with the sumproduct approach

    5 11 20 21 32 38 result is 30 when it should be 28
    and the array one was missing some $
    =SUM(VALUE(MID(A2&B2&C2&D2&E2&F2,ROW($A$1:OFFSET($A$1,LEN(A2&B2&C2&D2&E2&F2)-1,0)),1)))

  11. #11
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,655

    Re: Sum of digits of the numbers ?

    I've add $ in your formula and edited my post with disclaimer it doesn't work due to rounded numbers 10,20,30...
    But I won't fix it now since you formula works.

+ 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