4 / 6 · Intro
Adding up with SUM
If one cell in a column holds the text n/a, =B2+B3+B4 shows #VALUE!, while =SUM(B2:B4) skips the text and adds the rest.
Jump to the 10 practice questionsYou will learn
- Add a range with SUM
- Spot text that SUM silently skips
Before this: Writing your first formulas
1Explain
Your first function
A function is a named calculation that takes inputs in brackets. SUM adds numbers. Its inputs, called arguments, can be numbers, cell references, ranges or any mix: =SUM(4,6), =SUM(B2:B13) and =SUM(B2:B13,D2) all work. Commas separate the arguments. Microsoft's page says Excel's SUM takes up to 255 of them, and Google's help says Sheets accepts any number. In practice one or two ranges are enough, because a single range can cover thousands of cells.
2Problem
=SUM(4,6,10)
What does =SUM(4,6,10) return?
Hint
4 + 6 + 10.
Solution
Answer: 20
Typed numbers can be arguments too: 4 + 6 + 10 = 20.
3Problem
Arguments in Excel
How many numbers can Excel's SUM take as separate arguments?
Hint
The number from the paragraph.
Solution
Answer: 255
Microsoft: number1 to number255. Google Sheets has no fixed limit.
4Explain
SUM or a chain of plus signs
Writing =B2+B3+B4+B5+B6 gives the same total as =SUM(B2:B6) when every cell holds a number, but Microsoft lists reasons to prefer SUM. The long version is easy to mistype. It breaks with #VALUE! if any of the cells holds text, because + must turn every piece into a number and cannot turn n/a into one. SUM ignores text values in a range and adds only the numbers. And when you insert a row inside the range, SUM grows to include it, while a chain of + signs does not.
B4 holds text, shown on the left. =SUM(B2:B6) in B7 skips it and gives 455; =B2+B3+B4+B5+B6 would give #VALUE!.
5Problem
SUM over a text cell
B2:B6 holds 120, 95, the text n/a, 130 and 110. What does =SUM(B2:B6) return?
Hint
120 + 95 + 130 + 110.
Solution
Answer: 455
SUM skips the text: 120 + 95 + 130 + 110 = 455.
6Problem
The plus chain
Same cells. What does =B2+B3+B4+B5+B6 return?
Hint
+ cannot turn n/a into a number.
Solution
Answer: #VALUE!
+ has to turn n/a into a number and cannot.
7Explore
The same in JavaScript
The first way keeps only numbers, like SUM. The second adds everything: JavaScript has no #VALUE!, so the text glues the numbers into one long string.
const cells = [120, 95, "n/a", 130, 110];
console.log(cells.filter((c) => typeof c === "number").reduce((a, b) => a + b, 0));4558Explain
When skipping text hurts
Skipping text is helpful and dangerous at the same time. If a figure was typed as text by mistake, such as a number pasted with a stray space or apostrophe, SUM leaves it out without any warning and the total is simply too small. The left alignment from the previous unit is the clue to look for, and the lab's panel shows the kind of every value a formula used.
9Problem
A price pasted as text
A price was pasted as text by mistake. What does SUM do with it?
Hint
No warning at all.
Solution
Answer: Leaves it out without warning
Text in a range is ignored, so the total is quietly too small.
10Explain
Colons and commas
The colon and the comma do different jobs. B2:B6 means every cell from B2 to B6, five cells. B2,B6 means just those two cells. Microsoft calls them the range operator and the union operator. So =SUM(B2:B3,B6) adds three cells, B2, B3 and B6. One more detail: in some languages and regions the comma is used as the decimal mark, and there the spreadsheet expects semicolons between arguments, as in =SUM(B2:B3;B6). The rule is the same, only the separator changes.
11Problem
The colon
What does the colon in B2:B6 mean?
Hint
Every cell from one corner to the other.
Solution
Answer: Every cell from B2 to B6
The colon includes both endpoints and every cell between them, unlike a comma that separates individual arguments.
12Problem
B2:B3,B6
How many cells does =SUM(B2:B3,B6) add?
Hint
Two from the range, one more.
Solution
Answer: 3
B2:B3 is two cells, plus B6.
13Problem
Their total
With 120, 95 and 110 in B2, B3 and B6, what does =SUM(B2:B3,B6) return?
Hint
120 + 95 + 110.
Solution
Answer: 325
120 + 95 + 110 = 325.
14Problem
Comma as the decimal mark
In regions that use a comma as the decimal mark, how are SUM arguments separated?
Hint
A different separator.
Solution
Answer: Semicolons
=SUM(B2:B3;B6): only the separator changes.
15Explain
AutoSum and the total row
Both programs have a sum button marked with the Greek letter Σ. In Excel it is AutoSum on the Home tab; in Google Sheets it is in the Functions menu on the toolbar. Select the cell under a column of numbers, press it, and the program proposes a range. Check the proposed range before pressing Enter, because it stops at the first empty cell or label it meets. Selecting a block of numbers also shows their sum at the bottom of the window, which is handy for a quick look without writing anything.
16Problem
=SUM(A1:A4)/4
A1:A4 holds 2, 4, 6 and 8. What does =SUM(A1:A4)/4 return?
Hint
20 ÷ 4.
Solution
Answer: 5
20 / 4 = 5, the average. The AVERAGE function does this in one step.
17Explore
Practice in the grid
A good habit is to keep totals out of the range they add up. If the total for B2:B6 sits in B7 and the formula is =SUM(B2:B7), it includes itself, which is a circular reference and produces an error or a warning. Put a label such as Total in the cell to the left of the result so readers know what the number is, and leave the column of figures with nothing but figures in it. Then both SUM and anyone reading the sheet can trust the column.
Drag to turn. Scroll or pinch to zoom.
18Practice
A SUM that skips text
Finish sumNumbers(cells) so that it adds only the numbers and skips text, like SUM. With no numbers at all it returns 0.
455
20
0function sumNumbers(cells) {
let total = 0;
for (const c of cells) total += c;
return total;
}
console.log(sumNumbers([120, 95, "n/a", 130, 110]));
console.log(sumNumbers([4, 6, 10]));
console.log(sumNumbers(["x", "y"]));
Hint
typeof c === "number" is true only for numbers.
A solution
function sumNumbers(cells) {
let total = 0;
for (const c of cells) {
if (typeof c === "number") total += c;
}
return total;
}
console.log(sumNumbers([120, 95, "n/a", 130, 110]));
console.log(sumNumbers([4, 6, 10]));
console.log(sumNumbers(["x", "y"]));19
Summary
- =SUM(range) adds the numbers in a range and skips text.
- A chain of + signs breaks with #VALUE! when a cell holds text.
- Colon = range, comma = separate pieces.
- Excel SUM takes up to 255 arguments; Google Sheets has no fixed limit.