Sub topic 1
Cells and ranges: what you pass to a function
Every aggregate function in Google Sheets works on cells. Before you write SUM, AVERAGE, COUNT, MIN, or MAX, you need to know how to point at the cells you want. This chapter covers cell references and ranges, the two kinds of input that every later chapter relies on.
Prerequisites
This chapter assumes you can already do the following:
- Enter values and formulas in a Google Sheets spreadsheet, including starting a formula with
=. - Read cell addresses such as
B2, where the letter is the column and the number is the row. - Tell the difference between a number, a piece of text, and an empty cell.
You do not need to know any functions yet. The next chapter covers how a function call is written.
Cell references
A cell reference is the address of one cell. It has a column letter followed by a row number. B2 means column B, row 2.
When you use a reference in a formula, Sheets reads the current value of that cell. If the value changes, the formula result changes too. This is why spreadsheets are useful: you write the formula once, and it stays correct as the data changes.
=B2If B2 holds 40, this formula shows 40. If you change B2 to 55, the formula shows 55 right away.
You can also combine references with ordinary operators:
=B2+B3This works for two cells. It does not scale well to fifty cells. Ranges solve that problem.
What a range is
A range is a rectangular block of cells, written as two corner cells joined by a colon. The first corner is the top left and the second is the bottom right.
B2:B6This means "every cell from B2 down to B6", which is five cells: B2, B3, B4, B5, and B6. The colon reads as "through".
A range does not have to be a single column. It can be a row, or a block that spans several rows and columns.
| Range | What it covers | Number of cells |
|---|---|---|
| `B2` | One cell | 1 |
| `B2:B6` | One column, rows 2 through 6 | 5 |
| `B2:D2` | One row, columns B through D | 3 |
| `B2:D6` | A block, three columns by five rows | 15 |
The size of a block is the number of columns times the number of rows. B2:D6 covers columns B, C, and D (3) and rows 2 through 6 (5), so 3 × 5 = 15 cells.
The order of the corners
Sheets accepts the corners in either order. B6:B2 describes the same cells as B2:B6. When you type a range, Sheets normalizes it in the formula bar. Writing the top left corner first is the convention, and it makes formulas easier to read.
A worked example
Suppose a small sales sheet looks like this.
| Row | A | B | C |
|---|---|---|---|
| 1 | Product | Units sold | Returns |
| 2 | Apples | 120 | 4 |
| 3 | Pears | 85 | 2 |
| 4 | Plums | 60 | 0 |
| 5 | Cherries | 140 | 6 |
| 6 | Grapes | 95 | 3 |
The numbers for units sold sit in B2:B6. The header in B1 is text, so it is left out of the range on purpose. Ranges for calculations should usually start at the first data row.
Here are three ways to point at this data:
B2:B6is the five units-sold values.C2:C6is the five returns values.B2:C6is both columns together, ten cells.
Later chapters pass these ranges to functions. For now, notice that you describe the data once with a range, and the function does the rest.
How a range reaches a function
A range is not a list of separate numbers typed into the formula. It is a single input that stands for a block of cells. A function that accepts ranges reads every cell in the block and decides what to do with each one.
The important point is that the function, not the range, decides how to treat each cell. A range only says which cells to look at. One function may skip text cells and another may count them. The chapter on text, blanks, and zeros covers those differences.
Building ranges without typing
You can create a range in three ways. All of them produce the same text in the formula.
- Type it. Type
B2:B6directly after the opening parenthesis of a function. - Drag. While editing a formula, click the first cell and drag to the last. Sheets writes the range for you and highlights the cells with a colored border.
- Select first. Select the cells before you start the formula. This is the quickest way to fill in a range and avoids typos.
Dragging is convenient, but check the formula bar afterward. A drag that is one row short silently leaves a value out of your result.
References that move: relative and absolute
When you copy a formula to another cell, Sheets shifts its references by the same distance. This is called a relative reference. If you copy a formula from D2 to D3, a reference to B2 becomes B3.
A dollar sign locks part of a reference so it does not shift:
| Style | Example | Behavior when copied |
|---|---|---|
| Relative | `B2` | Column and row both shift |
| Absolute | `$B$2` | Neither shifts |
| Mixed, row locked | `B$2` | Column shifts, row stays |
| Mixed, column locked | `$B2` | Row shifts, column stays |
The same rules apply to ranges, since a range is two references. $B$2:$B$6 stays on the same five cells wherever you copy the formula. B2:B6 copied one column to the right becomes C2:C6.
This matters for aggregates. A total that you copy across a row of columns usually should use relative columns, so each column sums its own data. A range that points at a fixed lookup block should be absolute.
Referring to other sheets
A range can point at a different tab in the same spreadsheet. Put the sheet name, an exclamation mark, and then the range:
Sales!B2:B6If the sheet name contains spaces or special characters, wrap the name in single quotes:
'Q4 Sales'!B2:B6Forgetting the quotes on a name with a space is a common cause of a #ERROR! result. Sheets usually adds the quotes for you if you build the range by clicking, which is another reason to prefer selecting over typing for cross-sheet references.
Edge cases and common mistakes
- Including the header.
B1:B6includes the text inB1. Many functions skip text, so the result may still look right, but the habit is risky. Functions that count cells, covered later, will treat that header differently. - Off-by-one endings. If you add a new row below
B6and do not extend the range, the new row is not included. Inserting a row inside the range, between rows 2 and 6, extends it automatically. Adding a row after the last row does not. - Mixing up the colon and the comma. A colon builds a range. A comma, covered in a later chapter, separates different arguments.
B2:B6is one block.B2,B6is two separate cells. - Reversed intent with blocks.
B2:C6is a block of two columns. If you meant only the first and last columns of a wider table, you need separate arguments, not one block. - Stray empty rows. A range includes empty cells in its area. They are part of the range even if they hold nothing. Whether they affect a result depends on the function.
Naming a range
For ranges you reuse often, Google Sheets lets you give the range a name. Select the cells, then open Data and choose Named ranges. After you name B2:B6 as UnitsSold, you can write UnitsSold wherever you would write the address.
Named ranges make formulas easier to read, and they keep working if you move the data. They are optional, and this tutorial uses plain addresses so you can always see which cells are involved.
Check your understanding
Exercise
How many cells does the range C3:E7 cover, and how would the range change if you copied a formula containing C3:E7 two rows down?
Show answer
The range covers 3 columns (C, D, E) times 5 rows (3 through 7), so 15 cells. Because the references are relative, copying the formula two rows down shifts the range to C5:E9, which still covers 15 cells.
Exercise
A formula uses $B$2:$B$6. You copy it from D2 to E2. Which range does the copy use? What would the copy use if the original were B2:B6?
Show answer
The copy still uses $B$2:$B$6 because both the columns and rows are locked. With B2:B6 the copy would use C2:C6, since the column shifts one to the right.
Exercise
Your data is in B2:B6, and you add a new value in B7, directly under the range. Is B7 part of B2:B6? What would you need to do?
Show answer
No. Adding a value just after the end of a range does not extend it. You would edit the range to B2:B7, or insert the new row inside the range so Sheets expands it.