**Please Note: **
This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), *this tip may not work for you*. For a version of this tip written specifically for later versions of Excel, click here: Summing Digits in a Value.

If you have a cell that contains a value, you may want to devise a way to add together all the digits in the value. For instance, if a cell contains the value 554, you might want to determine the sum of 5+5+4, which is 14.

There are several ways you can approach this task. (Doesn't that always seem the way in Excel?) The first is to use a formula that relies on several functions:

=SUMPRODUCT(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))

This regular formula will sum the digits in any integer value (in cell A1) in a simple, elegant manner. This is not the only possible formula, however. The following is an array formula (terminated by pressing **Ctrl+Shift+Enter**) version of the same formula:

=SUM(1*MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))

Either of these formulas work fine if the value in A1 is a positive whole number. If there are any non-digit characters in the number (such as a negative sign or a decimal point), then the formulas return a #VALUE! error.

These are not the only formulas possible for this type of calculation. You can find some other examples of formulas in the Microsoft Knowledge Base:

http://support.microsoft.com/kb/214053

You can also use a user-defined function to return the desired sum. The following macro steps through each digit in the referenced cell and calculates a total. This value is then returned to the user:

Function AddDigits(Number As Long) As Integer Dim i As Integer Dim Sum As Integer Dim sNumber As String sNumber = CStr(Number) For i = 1 To Len(sNumber) Sum = Sum + Mid(sNumber, i, 1) Next AddDigits = Sum End Function

To use this function, just use a formula such as =AddDigits(A1) in a cell. An even more compact user-defined function (invoked in the same manner) is the following:

Function AddDigits(ByVal N As Long) As Integer Do While N >= 1 AddDigits = AddDigits + N Mod 10 N = Int(N / 10) Loop End Function

Unlike the earlier macro, this version doesn't convert the cell contents to a string in order to process it. Instead, it steps through each digit of the value, stripping off the last digit and adding it to the total.

*Note:*

If you would like to know how to use the macros described on this page (or on any other page on the *ExcelTips* sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

*ExcelTips* is your source for cost-effective Microsoft Excel training.
This tip (2424) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: **Summing Digits in a Value**.

**Program Successfully in Excel!** John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out *Excel 2013 Power Programming with VBA* today!

Want to know how to move pieces of information contained in one cell into individual cells? This option exists in using ...

Discover MoreWant to know the letters assigned by Excel to a particular column? Excel normally deals with column numbers, but you can ...

Discover MoreYou can easily sum a series of values in Excel, but it is not so easy to sum the absolute values of each value in a ...

Discover More**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

2018-05-07 14:36:38

David

The link to http://support.microsoft.com/kb/214053

Returned a Page Not Found error....

2018-04-05 17:16:54

Agarwal

can you please help me to undestand this formula, functions. Because this only give digits sum but i need digits sum in a single digit. And i also want to do some more things with this. Please sir help me to find solution of this issue.

Regards

2018-02-21 00:21:59

Kaushal

I expect answer is 153 means 1+5+3 = 9

How to do total with formula particular in 1 Cell

2017-05-11 10:57:09

Deshaun M Montgomery

{fig}

2017-01-09 15:06:53

Wow--it works! thank you!

2016-08-06 23:08:36

Jaan

SUM OF TWO CELLS A1 AND C1 FOR EXAMPLE IS 1234 IN CELL B2. NOW I WANT IN THE SAME CELL B2 FIRST THREE DIGITS SHOULD REMOVE LEAVING THE DIGIT 4 ONLY IN CELL B2.

YOUR HELP WILL HIGHLY APPRECIATED.

THANK YOU SO MUCH.

JAAN

2016-01-26 00:02:09

Haris

I'm experiencing trouble with having too large of numbers for Excel to handle. To give you an example, I need Excel to handle a number such as the following without rounding it off:

Number I need - > 0.00000067055225372314453125 - > Sum of all digits = 72

Excel Outputs - > 0.00000067055225372314500000 - > Sum of all digits = 56

Excel rounds off digits which skews my data by a lot because I need to have the sum of all digits of the entire number.

I need 2 things:

1. 0.00000067055225372314453125 / 2 - > simply to be able to divide a large format number such as this one by 2 and get the actual result by somehow manipulating it to be in text format. It needs to be a text format to begin with, treat it as a number and divide it by 2 then convert back to text format so that all the digits actually exist.

2. Then I need to get the sum of all the digits of the result in one particular cell that unfortunately has to be formatted as text in order to have all the digits.

This would be easier if the cell was formatted as a number, but the number ends up too large for excel to handle so my result ends up wrong.

I hope this makes sense :)

Thanks so much in advanced,

Haris

2015-04-12 12:45:36

Willy Vanhaelen

Function AddDigits(Number As String) As Integer

Dim i As Integer, Char As String

For i = 1 To Len(Number)

Char = Mid(Number, i, 1)

If IsNumeric(Char) Then AddDigits = AddDigits + Char

Next

End Function

2015-04-11 06:18:13

JOAN SQUIRES

2013-05-14 09:25:59

awyatt

As this tip says, it is for Excel 97 through Excel 2003. If you want to see how it works in Excel 2010, click the link at the end of the tip which says "You can find a version of this tip for the ribbon interface..."

-Allen

2013-05-13 11:20:27

Tzvetin Kmeski

My Excel version is 2010 and unfortunately this tip doesn't work.

How this tip will looks for excel 2010?

Thanks,

Tzvetin.

2013-01-10 06:46:25

Thanks for this, Excellent one.

=SUMPRODUCT(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))

I would like to explore withing the same formula, how can we get the result to one single digit or reduce to one single digit.

Rajesh

2012-12-26 06:31:39

Keith Griffiths

http://excel.tips.net/T002424_Summing_Digits_in_a_Value.html

there is this formula for producing sums of digits in a value:

=SUMPRODUCT(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))

However I would like to multiply the digits of the value within a cell. i.e. if A1 is 456 a formula would produce 120. I recognize that a zero digit would make the result zero so the formula would have to ignore zeros. to get the result of the remaining non-zero digits.

Would appreciate any ideas.

2012-08-22 13:23:12

Rick Rothstein

Function DigitSum(S As String) As Long

DigitSum = Evaluate(Replace(StrConv(S, vbUnicode), Chr(0), "+") & "0")

End Function

Obviously, large "numbers" have to be formatted as text. The function will successfully handle a text string of up to 127 digits.

@Armando and Houdini,

That UDF and those formulas do not do the same thing as the UDF that Allen posted... Allen's UDF (and the one I posted above) sums the digits whereas as yours do a "casting out 9's" summation of digits... they are not the same thing.

2012-08-11 08:17:19

Armando Montes

http://www.mrexcel.com/forum/showthread.php?t=622330&page=2

Function Quick(ByVal number)

Quick = (number - 1) Mod 9 + 1

End Function

Same as formula

=MOD(A1-1,9)+1

HOUDINI:

That formula works for me but note that it will fail for values of A1 greater than 1207959552 (because MOD function returns an error in that case)

This version can cope with larger numbers

=A1-FLOOR(A1-1,9)

Got a version of Excel that uses the
menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)?
**This site is for you!** If you
use a later version of Excel, visit
our *ExcelTips* site focusing on the ribbon interface.

**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

Copyright © 2018 Sharon Parq Associates, Inc.

## Comments