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

# Summing Digits in a Value by Allen Wyatt
(last updated May 6, 2020)

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/?kbid=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
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 (12002) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel 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

Selecting Text Orientation for an Axis in Microsoft Graph

Microsoft Graph allows you to easily create charts from numeric data, without the need to use Excel. This tip explains ...

Discover More

Stepping Through a Non-Contiguous Range of Cells

Using macros to step through each cell in a selection is a common occurrence. What if that selected range is made up of ...

Discover More

Adjusting to a Maximum Row Height

Need to check the height of all the rows in a worksheet and then adjust them if a particular criterion is met? This tip ...

Discover More Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

##### More ExcelTips (ribbon)

Selective Summing

If you want to add up the contents of a range of cells based on what is contained in a different range of cells, you need ...

Discover More

Counting Unique Values with Functions

Using Excel to maintain lists of information is not unusual. When working with the list you may need to determine how ...

Discover More

Moving the House Number to Its Own Cell

Excel is great at manipulating data, but sometimes it is difficult to figure out the best way to do the manipulation. ...

Discover More
##### Subscribe

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

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}] (all 7 characters, in the sequence shown) 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 four minus 4?

2021-04-11 05:27:51

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)
Next
End Function

2020-05-09 06:53:47

Peter Atherton

As a child we had a game to sum the digits until a single figure was arived at. Here is the function

Dim i As Integer, Char As Integer
Dim tmp, tmp2
For i = 1 To Len(value)
Char = Mid(value, i, 1) * 1
If IsNumeric(Char) Then tmp = tmp + Char
Next i
Do

For i = 1 To Len(tmp)
Char = Mid(tmp, i, 1)
tmp2 = tmp2 + Char
Next i
If tmp2 > 10 Then
tmp = tmp2
tmp2 = 0
Else
Exit Do
End If
Loop Until tmp < 10

End Function

2020-05-09 00:51:03

HARISH GUPTA M.R

Thanks for the Tips Allen,
I have designed a formula which can sum of numbers in a cell which can contain Alphanumeric.
Eg-> If Cell A1 has text "D25R67T726B"
Formula to get sum of numbers would be =SUM(IF(ISNUMBER(VALUE(MID(A16,ROW(INDIRECT("1:"&LEN(A16))),1)))=TRUE,VALUE(MID(A16,ROW(INDIRECT("1:"&LEN(A16))),1)),0))
This is a array formula[should be pushed with CTRL+SHIFT+ENTER]

To get only a count of numbers in a cell would be.
=SUMPRODUCT(--ISNUMBER(VALUE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))))
This can be pushed by a normal enter button.

Thanks
Harish

2016-11-06 07:36:04

Michael (Micky) Avidan

The following Array Formula should fulfil the task (even for decimal and/or negative numbers):
=SUM(IFERROR(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),))
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)
ISRAEL

2016-11-05 06:46:46

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)
Next
End Function

##### This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.