Microsoft Office Tutorials and References
In Depth Information
Chapter 15: Performing Magic with Array Formulas
Summing the digits of an integer
I can’t think of any practical application for the example in this section, but it’s a good
demonstration of the power of an array formula. The following array formula calculates the sum of the
digits in a positive integer, which is stored in cell A1. For example, if cell A1 contains the value
409, the formula returns 13 (the sum of 4, 0, and 9).
To understand how this formula works, start with the ROW function, as shown here:
This function returns an array of consecutive integers beginning with 1 and ending with the
number of digits in the value in cell A1. For example, if cell A1 contains the value 409, the LEN
function returns 3, and the array generated by the ROW functions is
For more information about using the INDIRECT function to return this array, see
This array is then used as the second argument for the MID function. The MID part of the formula,
simplified a bit and expressed as values, is the following:
This function generates an array with three elements:
By simplifying again and adding the SUM function, the formula looks like this:
This formula produces the result of 13.
The values in the array created by the MID function are multiplied by 1 because the MID
function returns a string. Multiplying by 1 forces a numeric value result. Alternatively,
you can use the VALUE function to force a numeric string to become a numeric value.