Sum code
| A | |
|---|---|
| 1 | Value |
| 2 | 2 |
| 3 | 4 |
| 4 | 6 |
| 5 | 8 |
Formula: C2: =SUBTOTAL(9,A2:A5)
Result: 20
Code 9 selects SUM for the referenced values.
SUBTOTAL with worked examples you can test in the live grid. The argument details are in the Excel guide.
The arguments and common errors are covered in the SUBTOTAL Excel guide; check the function help in Google Sheets for its own argument list.
| A | |
|---|---|
| 1 | Value |
| 2 | 2 |
| 3 | 4 |
| 4 | 6 |
| 5 | 8 |
Formula: C2: =SUBTOTAL(9,A2:A5)
Result: 20
Code 9 selects SUM for the referenced values.
| A | |
|---|---|
| 1 | Value |
| 2 | 2 |
| 3 | 4 |
| 4 | 6 |
| 5 | 8 |
Formula: C2: =SUBTOTAL(2,A2:A5)
Result: 4
Code 2 counts the numeric cells.
| A | |
|---|---|
| 1 | Amount |
| 2 | 3 |
| 3 | 4 |
| 4 | =SUBTOTAL(9,A2:A3) |
Formula: C2: =SUBTOTAL(9,A2:A4)
Result: 7
A4 is itself a subtotal of 7, so it is not added again. SUM(A2:A4) would give 14.
A tiny spreadsheet with example data. Edit the formula or any number and see the result.
Formula in F2: =SUBTOTAL(9,C2:C7)
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Region | Product | Units | Price | Result | |
| 2 | East | Pen | 120 | 2.5 | 350 | |
| 3 | West | Pen | 80 | 2.5 | ||
| 4 | East | Book | 45 | 12 | ||
| 5 | North | Book | 60 | 12 | ||
| 6 | West | Lamp | 30 | 25 | ||
| 7 | East | Lamp | 15 | 25 |
Google Sheets is used here only as a descriptive product name. FormulaCamp is not affiliated with Google.
Enter — commit · F2 — edit · F4 — $ in a reference · Ctrl+C/Ctrl+V — copy and paste · Ctrl+Z — undo
Esc or F6 — leave the sheet for the «Check» button · Shift+Tab in the first cell — back to the page