+ Reply to Thread
Results 1 to 11 of 11

Calculate sum of digits in a number string

  1. #1
    Forum Contributor PRADEEPB270's Avatar
    Join Date
    02-19-2010
    Location
    INDIA
    MS-Off Ver
    MSoffice-2016
    Posts
    332

    Calculate sum of digits in a number string

    I need to calculate the sum of digits in a numeric string. The function should keep on adding the digits of each result, till the final sum is a single digit. Please refer to the following example and result expected:-

    Supposed the number entered in Cell A1 is 456789

    Result 1 = 4+5+6+7+8+9 = 39

    Result 2 = 3+9 = 12

    Final Result required = 1+2 = 3

    Regards

    Pradeep Kumar Gupta
    Last edited by PRADEEPB270; 03-04-2010 at 06:03 AM.

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

    Re: Calculate sum of digits in a number string

    Compliments of DLL, in some distant thread:

    =A1 - FLOOR(A1 - 1, 9)
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor PRADEEPB270's Avatar
    Join Date
    02-19-2010
    Location
    INDIA
    MS-Off Ver
    MSoffice-2016
    Posts
    332

    Re: Calculate sum of digits in a number string

    Sir,I am not clear with this formula.Can you solve this problem on a work sheet ?

    Regards

    Pradeep

  4. #4
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Calculate sum of digits in a number string

    hello,

    Here is a function that will do what you are after,
    Please Login or Register  to view this content.
    cheers

    I would take the DLL function , It should be a lot faster that the UDF. The power of excel :P
    Last edited by D_Rennie; 02-23-2010 at 02:01 AM.


  5. #5
    Forum Contributor PRADEEPB270's Avatar
    Join Date
    02-19-2010
    Location
    INDIA
    MS-Off Ver
    MSoffice-2016
    Posts
    332

    Re: Calculate sum of digits in a number string

    Please accept my apolozies to written again about not clear.Now the formula is working fine.I am obliged.

    Regards

    Pradeep

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

    Re: Calculate sum of digits in a number string

    Quote Originally Posted by shg View Post
    Compliments of DLL, in some distant thread:

    =A1 - FLOOR(A1 - 1, 9)
    er...FWIW... wow....

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

    Re: Calculate sum of digits in a number string

    Actually, it's an example of a more general process (see http://www.mathpages.com/home/kmath020.htm and http://mathforum.org/k12/mathtips/mulliss.html ), and the simpler solution is =MOD(A1 - 1, 9) + 1.

    DLL's alternative circumvents a bug in the MOD function described at http://support.microsoft.com/kb/119083. I don't know whether it persists to later versions.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Calculate sum of digits in a number string

    Quote Originally Posted by shg View Post
    Compliments of DLL, in some distant thread:

    =A1 - FLOOR(A1 - 1, 9)
    Every now and then, the elegance of a solution makes my jaw drop. As DO said..."wow"!
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  9. #9
    Registered User
    Join Date
    10-20-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Calculate sum of digits in a number string

    Thank you,

    the formula is very helpful, is there a way to get the all 4 digit numbers with total 9?

    regards
    sam

  10. #10
    Registered User
    Join Date
    09-11-2012
    Location
    Toronto
    MS-Off Ver
    Excel Starter
    Posts
    5

    Re: Calculate sum of digits in a number string

    Sorry to bring back this thread from almost a year ago, but I'm having trouble with this formula. It works great when the number turns into anything but a 0. In that case, it turns into a 9. Is there any way to keep the zero in the formula?

    Example:
    32 (3+2=5) shows 5.
    92 (9+2=11, 1+1=2) shows 2.
    0 (0) shows 9.

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Calculate sum of digits in a number string

    Gavald229,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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