Sub topic 3
Adding values with SUM
This chapter assumes you can enter values in cells, select ranges with the mouse or keyboard, and know that a formula starts with an equals sign. It also assumes you have read the previous chapters on cells, ranges, and function syntax.
What SUM does
SUM adds the numbers in the arguments you give it and returns one number. An argument can be a single cell, a range, a typed constant, or a mix of these.
The sample data used here is a small sales table. Column A holds the region, column B holds the amount, and the amounts sit in B2:B6.
| Cell | A (Region) | B (Amount) |
|---|---|---|
| 1 | Region | Amount |
| 2 | East | 120 |
| 3 | West | 80 |
| 4 | East | (blank) |
| 5 | North | n/a |
| 6 | East | 150 |
The following formula adds the range:
=SUM(B2:B6)The result is 350. The blank cell in B4 and the text n/a in B5 are ignored. SUM only adds the numeric values it finds inside a range.
Several arguments
SUM accepts many arguments, separated by commas. Each one is added to the total.
=SUM(B2:B6, D2:D6, 100)This adds every number in B2:B6, every number in D2:D6, and the constant 100. Use this form when your data sits in separate blocks. It is cleaner than chaining plus signs, and it skips text in ranges instead of failing.
Text typed directly as an argument
The rule that text is ignored applies to cells inside a range or referenced by a cell address. A text value typed straight into the formula behaves differently.
=SUM("5", 10)Excel converts the text "5" to a number here, so the result is 15. Text that cannot be converted, such as "abc", returns a #VALUE! error. Numbers stored as text inside a range are a common source of totals that look too low. Check for them if a total seems wrong.
Keeping the range fixed when you copy
When you copy a formula, Excel shifts its references. If the total must keep pointing at the same range, anchor it with absolute references:
=SUM($B$2:$B$6)The dollar signs lock the column and row. Copy this formula anywhere and it still adds B2:B6. This matters when many cells need to refer to the same data block.
Common errors
- Wrong range after inserting rows. If you insert a row inside the range, Excel expands it. If you add data directly below the last cell, the range does not grow. Extend it by hand or use a larger range.
- Totals that ignore numbers. Values stored as text, often left-aligned with a small green triangle, are skipped. Convert them to numbers.
- Errors in the range. If any cell in the range holds an error such as
#N/A,SUMreturns that error. Fix the source cell. - Overlapping ranges.
=SUM(B2:B6, B4:B8)counts the cells in B4:B6 twice.
Exercises
Exercise
B2:B6 contains 10, 20, a blank cell, the text "x", and 30. What does =SUM(B2:B6) return, and why?
Show answer
It returns 60. SUM adds only the numeric values in a range. The blank cell and the text "x" are ignored.
Exercise
You copy =SUM(B2:B6) from cell B8 to cell C8. What does the formula become, and how would you stop it changing?
Show answer
It becomes =SUM(C2:C6), because the references are relative and shift one column right. Write =SUM($B$2:$B$6) to keep it pointing at B2:B6.