+ Reply to Thread
Results 1 to 16 of 16

Sum of even digits

  1. #1
    Registered User
    Join Date
    08-13-2018
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Office 2016
    Posts
    4

    Cool Sum of even digits

    I have a challenge. I am pretty good in Excel myself but this one is a bit complex.

    I'd like to have the sum of even digit positions of a number. Example:
    1234567890
    then I'd like to get the following results:
    9+7+5+3+1=25

    So I was thinking to apply a digit mask (101010101010) first but it seems Excel doesn't have such an option except binary.

    If this would be possible then I can take the sum of all digits of the number.

    Of course a "nasty" solution would be to split the number to digits in rows and then in a new column detect if the row is even, if so then copy the value and then sum the column. But that takes a lot of calculations and I need to do this for tons of large numbers.

    Last but not least: I'd like to do this via a formula and not VBA.

    So I am now asking the Excel masters & guru's

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,659

    Re: Sum of even digits

    The digits you are summing are the ODD digits, not the even ones.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Valued Forum Contributor PeteABC123's Avatar
    Join Date
    09-21-2012
    Location
    Chicago, IL
    MS-Off Ver
    MS Office 365 ver 2202
    Posts
    1,104

    Re: Sum of even digits

    Could you upload a sanitized sample of your data, with raw data, and show your desired results?
    Pete

  4. #4
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,907

    Re: Sum of even digits

    Try this:

    =SUMPRODUCT(--MID(A1,ROW(INDIRECT("1:"&INT(LEN(A1)/2)))*2-ISEVEN(LEN(A1)),1))

  5. #5
    Registered User
    Join Date
    08-13-2018
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: Sum of even digits

    AliGW, no I am not. I guess you read odd values. I wrote odd digit positions.

    PeteABC123, that would make it overly complicated. What matters is this:
    I need to have a sum of all the even digit positions in a number.
    So as in my example:
    1234567890
    1010101010
    ----------
    1030507090

    Sum of all digits:
    1+0+3+0+5+0+7+0+9=25


    Or:
    6789
    1010
    ----
    6080

    Sum of all digits:
    6+0+8+0=14

  6. #6
    Registered User
    Join Date
    08-13-2018
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: Sum of even digits

    Phuocam: you are AWESOME!!!

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,720

    Re: Sum of even digits

    You can use this array* formula in B2, assuming your string of numbers is in A2:

    =SUM(IF((MOD(ROW($1:$10),2)=1),--(MID(A2,ROW($1:$10),1))))

    *Note that an array formula needs to be confirmed using the key combination of Ctrl-Shift-Enter (CSE), rather than the usual < Enter >

    Hope this helps.

    Pete

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,659

    Re: Sum of even digits

    No, I read this:

    I'd like to have the sum of even digit positions of a number. Example:
    1234567890
    then I'd like to get the following results:
    9+7+5+3+1=25
    The EVEN digit positions in the string you have quoted are 2, 4, 6, 8 and 0.

  9. #9
    Forum Contributor
    Join Date
    05-12-2018
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    266

    Re: Sum of even digits

    very confusing... You want the odd or the even digits to sum?

    UDF to sum the odd digits:

    Please Login or Register  to view this content.
    Change the red > to a = for the even digits
    Last edited by SjonR; 08-13-2018 at 10:06 AM.

  10. #10
    Registered User
    Join Date
    08-13-2018
    Location
    Amsterdam, Netherlands
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: Sum of even digits

    AliGW & SjonR, it seems I am wrong here about digit positions. The first digit seems to be called digit 0 by you guys as in programming languages. Sorry for the confusion. I just thought the first digit position of a number would be called 1. And the second digit would be position 2.
    Nevertheless the problem has been solved. Thanks a lot for the great help!

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,659

    Re: Sum of even digits

    No, I didn't say that!!! In your string 1234567890 there are 10 digits: the numbers you have used happen to coincide with their odd or even positions. If you had chosen the string 2345678901, then the digits in the odd positions would have been 2, 4, 6, 8 and 0.

    It's like this for a ten-digit string:

    ODD - EVEN - ODD - EVEN - ODD - EVEN - ODD - EVEN - ODD - EVEN

  12. #12
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,720

    Re: Sum of even digits

    I can see the OP's logic - the least significant digit (0) is the first digit position, the next least significant (9) is in position 2, and so on. He is just numbering the digits from the other end.

    In his other example (Post #5) of 6789, the 9 is in digit position 1, the 8 in 2, and so on.

    Hope this helps.

    Pete

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,659

    Re: Sum of even digits

    Oh, from right to left? Significant digits? Well, if he'd said that, I think we'd all have understood.

  14. #14
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: Sum of even digits

    I do find the OP's numbering system (back to front) a bit odd. However...

    the solutions provided don't seem to work for me for shorter strings. However, Pete's is easily modified. But my version works from LEFT to RIGHT.

    Edit: I am confusing myself... and would like to understand the logic behind starting from the right....
    Attached Files Attached Files
    Last edited by Glenn Kennedy; 08-13-2018 at 10:33 AM.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  15. #15
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,720

    Re: Sum of even digits

    Quote Originally Posted by Glenn Kennedy View Post
    ... and would like to understand the logic behind starting from the right....
    Glenn,

    consider building up a binary number by adding 1 each time - you would have this:

    a 0
    b 1

    this is bit 1

    c 10
    d 11

    we now have bits 2 and 1

    e 100

    and move into having bits 3, 2 and 1, and so on.

    Bit 1 is always the least significant bit, and the most significant bit has the largest bit position. Because we are used to reading left to right, this numbering seems odd, but it is logically consistent.

    Hope this helps.

    Pete

  16. #16
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,720

    Re: Sum of even digits

    Incidentally, you can amend my formula to this (changes in red):

    =SUM(IF((MOD(ROW($1:$10),2)=1),IFERROR(--(MID(A2,ROW($1:$10),1)),0)))

    to take account of numbers with fewer than 10 digits. Commit with CSE, as previously described.

    (the OP doesn't seem to be listening anymore).

    Hope this helps.

    Pete

+ 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. [SOLVED] Looking for a formula to count single digits vs. double digits?
    By mnlaw in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-29-2023, 02:20 PM
  2. Replies: 4
    Last Post: 11-09-2017, 02:05 PM
  3. [SOLVED] add 0 to numerical digits of 6 digits only in mixed alphanumerical columns
    By JEAN1972 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-11-2017, 01:35 PM
  4. [SOLVED] Combine digits in double digits in 4 numbers without repeating each other
    By jorel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-14-2014, 08:18 AM
  5. vlookup only the right most 4 digits of the 6 digits sequential numbers
    By tabcm66 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 05-02-2014, 07:33 AM
  6. [SOLVED] How to multiply a constant to only first 10 digits of 45 digits in a Logical Function
    By gz3s36 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-10-2014, 02:40 PM
  7. Changing digits after decimal to specific digits based on a criteria
    By mpatel000 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-28-2012, 02:41 AM

Tags for this Thread

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