Sub topic 3
Adding values with SUM
SUM is the function you will write most often in Excel. This chapter covers its syntax, what it does with each kind of cell content, and the mistakes that produce wrong totals without any warning.
This chapter assumes you can enter and edit values in cells, select cells and ranges with the mouse or keyboard, and you know that formulas start with an equals sign. It also assumes you have seen a cell reference like B2 and a range like B2:B6.
What SUM does
SUM adds the numbers in its arguments and returns the total. An argument is a value, cell reference, or range that you put inside the parentheses. The general form is:
=SUM(number1, [number2], ...)Only the first argument is required. Each argument can be a number, a single cell, or a range. Excel accepts up to 255 arguments in one SUM call.
Suppose column B holds monthly sales in B2:B6. This formula adds all five cells:
=SUM(B2:B6)The range B2:B6 means "every cell from B2 down to B6". SUM reads the contents of those cells, keeps the numbers, and adds them. It ignores blank cells and text in that range.
Using more than one argument
You can pass several arguments, and each one can be a different kind of thing. This formula adds two ranges and a constant:
=SUM(B2:B6, D2:D6, 100)Excel adds everything in B2:B6, everything in D2:D6, and then 100. Separate arguments with commas. In some regional settings, such as many European locales, Excel uses semicolons instead. If a formula you type is rejected, check which separator your installation expects.
Multiple arguments are useful when the cells you want are not next to each other. You can also mix single cells with ranges:
=SUM(B2, B4, B6, D2:D6)You can type the references, or you can build the formula by clicking. Type =SUM(, select the first range, type a comma, hold Ctrl and select the next range, and so on. Excel writes the references for you.
How the diagram of a SUM call fits together
The following diagram shows how Excel evaluates a SUM call, argument by argument.
The key point is that the same content is treated differently depending on how it reaches SUM. A reference is lenient. A typed value is strict.
What SUM does with each kind of content
The rules below are the source of most surprises. They connect to the later chapter on how blanks, text, logical values, and zeros affect every summary function, so this section covers only what matters for SUM.
| Content | Inside a range or cell reference | Typed directly as an argument |
|---|---|---|
| Number | Added | Added |
| Blank cell | Ignored | Not applicable |
| Text such as `"abc"` | Ignored | `#VALUE!` error |
| Text that looks like a number, such as `"5"` | Ignored | Converted to 5 and added |
| TRUE or FALSE | Ignored | TRUE counts as 1, FALSE as 0 |
| Error such as `#N/A` | Error is returned | Error is returned |
Two rows deserve extra attention.
The first is numbers stored as text. If a cell shows 250 but is left-aligned and has a small green triangle in its corner, Excel stored it as text. This often happens after you import data or paste from a web page. Because SUM ignores text inside a range, that cell silently drops out of the total. The formula returns no error, so the total is simply too low.
The second is error values. If any cell in the range holds #N/A, #DIV/0!, #REF!, or another error, SUM returns that same error. One bad cell spoils the whole total. This is called error propagation.
Here is a small data set that shows both problems:
| Row | A | B |
|---|---|---|
| 1 | Item | Amount |
| 2 | Pens | 10 |
| 3 | Paper | 20 |
| 4 | Ink | `'30` (text) |
| 5 | Tape | (blank) |
| 6 | Glue | 40 |
=SUM(B2:B6) returns 70, not 100. The text 30 in B4 is skipped, and the blank in B5 is skipped. Nothing on screen tells you a value was left out.
Finding numbers stored as text
You can detect the problem with two quick checks. Compare the count of non-empty cells with the count of numeric cells:
=COUNTA(B2:B6)
=COUNT(B2:B6)In the table above, COUNTA returns 4 (the blank is not counted) and COUNT returns 3. When the two numbers differ and you expected every filled cell to be a number, some cells hold text.
To fix the cells, you have several options:
- Select the cells, click the warning icon that appears, and choose Convert to Number.
- Select the column, open Data > Text to Columns, and click Finish without changing any settings. This re-reads each cell and converts text that looks like a number.
- Type
1in a spare cell, copy it, select the text cells, and use Paste Special > Multiply. Multiplying by 1 forces a conversion. - Wrap a reference in
VALUE()inside a helper column if you cannot change the source.
Whole-column references
You can sum an entire column by naming it without row numbers:
=SUM(B:B)This adds every number in column B, including rows you add later. It is convenient for lists that keep growing. It has two drawbacks. If a header or a total row sits in the same column, the total row is included and you create a circular reference when the formula itself is in that column. Also, whole-column references on very large workbooks that contain many such formulas can slow recalculation, though Excel limits the work to the used part of the sheet.
A common pattern is to put the total outside the column it sums, for example in D1, so that adding rows does not collide with it.
Copying SUM formulas: relative and absolute references
By default, references are relative. When you copy a formula, Excel shifts each reference by the same number of rows and columns as the move. If you copy =SUM(B2:B6) from B7 to C7, it becomes =SUM(C2:C6). This is what you want when each column has its own total.
Sometimes the range must stay fixed. A dollar sign locks the part of the reference that follows it. Use absolute references to keep the formula pointing at the same cells wherever you copy it:
=SUM($B$2:$B$6)Here $B$2:$B$6 never shifts. A mixed reference such as B$2:B$6 locks only the rows, so it still moves sideways. Press F4 while the cursor is in a reference to cycle through the four forms: B2, $B$2, B$2, and $B2.
Quick totals without writing a formula
Two shortcuts give you a sum without typing it.
- AutoSum. Select a cell below or to the right of a column or row of numbers and press Alt+= (Windows), or choose Home > AutoSum. Excel inserts a SUM formula with its best guess at the range and highlights that range. Check the highlighted range before you press Enter. AutoSum stops at the first blank cell or at text, so it can pick a shorter range than you intended.
- Status bar. Select a range and read the bottom-right of the window. Excel shows Average, Count, and Sum by default. Right-click the status bar to add Minimum, Maximum, and Numerical Count. The status bar writes nothing into the sheet, so use it to check a result or to look at a number you do not need to keep.
The status bar sum is also a good cross-check. If it disagrees with your formula, one of them is reading a different range.
Other ways SUM goes wrong
- Overlapping ranges.
=SUM(B2:B6, B4:B8)counts B4:B6 twice. SUM does not remove duplicates between arguments. - A range that does not include new rows. If you insert a row inside the range, Excel expands it. If you add a row directly below the last cell, the range does not grow. Sum a whole column, or insert new rows between existing ones.
- Subtotals inside the range. If your range includes a subtotal row and the detail rows above it, every value is counted twice. The SUBTOTAL function, covered in a later chapter, avoids this.
- Hidden and filtered rows. SUM includes hidden rows. If you filter a list and expect the total to match what you see, SUM will give a larger number. Again, SUBTOTAL handles this.
- Floating-point display. Excel stores numbers in binary, so a sum such as 0.1 plus 0.2 can carry tiny errors beyond 15 digits. If you compare a SUM to another value with
=, wrap both sides inROUND.
Going further
When you need to add only the cells that meet a condition, use SUMIF:
=SUMIF(A2:A6, "East", B2:B6)This adds the values in B2:B6 whose matching cell in A2:A6 equals East. The conditional functions are the topic of a later chapter. For now, recognize the signal: if you find yourself adding cells by hand because only some of them qualify, you need a conditional function.
Summary
SUM(number1, [number2], ...)accepts up to 255 arguments that can be numbers, cells, or ranges.- Inside a range, SUM skips blanks, text, and logical values. Typed text that cannot be read as a number causes
#VALUE!. - Numbers stored as text are the most common cause of totals that are too low. Compare COUNT and COUNTA to find them.
- An error anywhere in the range makes SUM return that error.
- Use
$to keep a range fixed when copying, and check AutoSum's chosen range before accepting it.
Exercise
A column B2:B8 holds the values 5, 15, "20" (text), a blank cell, 10, #N/A, and 30 in that order. What does =SUM(B2:B8) return, and what would it return if the #N/A cell were fixed to hold the number 10?
Show answer
With the #N/A in place, SUM returns #N/A, because an error anywhere in the range is passed through. After fixing the cell to 10, SUM adds 5 + 15 + 10 + 10 + 30 = 70. The text "20" and the blank are skipped, so the total is 70, not 90. To find the missing 20, compare =COUNTA(B2:B8) with =COUNT(B2:B8) and convert the text cell to a number.
Exercise
You wrote =SUM(B2:B6) in cell B7 and copied it to C7, but you want C7 to still add column B. What change to the formula in B7 makes that work, and which key helps you type it?
Show answer
Change it to =SUM($B$2:$B$6). The dollar signs make the column and row parts absolute, so the reference does not shift when copied. Pressing F4 while the cursor is on or inside the reference adds the dollar signs.