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.

# Summing Digits in a Value

by Allen Wyatt
(last updated October 27, 2015)

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
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.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Setting a Spacing Adjustment in the Equation Editor

The Equation Editor is a handy tool when you are creating documents that rely on mathematical formulas. If you want to ...

Discover More

Printing Close to the Edge

Word allows you to specify all sorts of paper sizes and margins for your documents. If your margins result in trying to ...

Discover More

Ampersands in Headers and Footers

Add an ampersand to the text in a header or footer and you may be surprised that the ampersand disappears on your ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

##### More ExcelTips (menu)

Number of Terms in a Formula

Formulas are made up of operands that separate a series of terms acted upon by the operands. You may want to know, for ...

Discover More

Determining Winners, by Category

Do you need to determine the top three values in a range of columns? The techniques discussed in this tip will come in ...

Discover More

Summing Based on Formatting in Adjacent Cells

It is easy to use Excel functions to sum values based on criteria you establish, unless those criteria involve the ...

Discover More
##### Subscribe

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

View most recent newsletter.

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. Youâ€™ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one more than 5?

2018-05-07 14:36:38

David

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

2018-04-05 17:16:54

Agarwal

Dear Sir,

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 have Some digit or Value in particular 1 cell Ex. 153

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

Thank you for the simplistic answers. I have a similar challenge in a workbook. I am using a combination of Concatenate and Filter to return a string of numbers from one sheet to another into a single cell. I then need to sum the string so that I have a total for each filter criteria. The equations you provide work great until trying to sum numbers that are two digits such as "10,10" which displays as 1010 in the cell. I require a sum of 20 but receive a sum of 2. Is there any way around that.

{fig}

2017-01-09 15:06:53

Thomas Blanchard

Wow--it works! thank you!

2016-08-06 23:08:36

Jaan

If possible you can help me in writing a formula for the following:

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

Hi there,

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

Here is a user defined function that works with negative numbers and numbers with decimals as well:

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

Many thanks for this. I absolutely love playing with Excel and it is nice to know that when I get stuck there is an amazingly clever person like you out there to come to my rescue. Formula worked perfectly.

2013-05-14 09:25:59

awyatt

Tzvetin,

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

Hello,

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

Rajesh

Hey

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

From website:

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

There is a one-liner UDF (user defined function) that can do this...

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

Check this out:
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)

##### This Site

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.