Sub topic 1
Cells and ranges: what the functions read
SUM, AVERAGE, MIN, MAX, and COUNT all take cells as input. Before looking at each function, you need to know what a cell reference points to, how a range is built, and what Excel reads when a function receives one. Most surprising results in later chapters trace back to a misunderstanding here.
Prerequisites
This chapter assumes you can do the following:
- Type and edit values in worksheet cells.
- Select cells and ranges with the mouse or keyboard.
- Start a formula with an equals sign.
You don't need to know any function yet. Each of the five functions gets its own chapter.
Cells, addresses, and values
A cell is one box in the worksheet grid. Its address is its column letter followed by its row number, so B3 is column B, row 3. This style is called A1 notation.
A cell holds two things that can differ:
- The stored value or formula. This is what you see in the formula bar.
- The displayed text. This is what you see in the grid, after number formatting is applied.
Functions read the stored value, never the displayed text. Suppose a cell holds 2.5 and is formatted with zero decimal places. The grid shows 3, but SUM adds 2.5. Likewise, a cell holding 0.125 and formatted as a percentage shows 13%, and AVERAGE still uses 0.125.
This is a common cause of totals that look wrong by a small amount. The numbers on screen are rounded, and the total is computed from the unrounded values.
A cell can hold a number, text, a logical value (TRUE or FALSE), an error such as #N/A, or nothing at all. Which of these each function accepts is covered in a later chapter. For now, remember that a range can contain a mix of all of them.
What a range is
A range is a rectangular block of cells. You write it as the top-left cell, a colon, and the bottom-right cell. The colon is the range operator, and it means "every cell from here to there".
| Range | Meaning | Cells |
|---|---|---|
| `B2` | A single cell | 1 |
| `B2:B6` | One column, rows 2 to 6 | 5 |
| `B2:D2` | One row, columns B to D | 3 |
| `B2:D6` | A block, 3 columns by 5 rows | 15 |
| `B:B` | The whole of column B | 1,048,576 |
| `2:2` | The whole of row 2 | 16,384 |
| `B:D` | Columns B through D | 3 whole columns |
The corners can be given in either order. B6:B2 and B2:B6 mean the same range, and Excel normalizes both to B2:B6.
You can check the size of a range with ROWS and COLUMNS:
=ROWS(B2:D6)
=COLUMNS(B2:D6)
=ROWS(B2:D6)*COLUMNS(B2:D6)These return 5, 3, and 15. The count of cells in a range is rows times columns, whether or not those cells contain anything.
A sample worksheet
The examples in this tutorial use a small sales list. Here is the layout, with the cell address of each entry in mind:
| Row | A | B | C |
|---|---|---|---|
| 1 | Region | Sales | Notes |
| 2 | East | 120 | |
| 3 | West | 95 | late |
| 4 | East | (blank) | |
| 5 | North | 210 | |
| 6 | West | 80 |
Cells B2:B6 hold the numbers 120, 95, nothing, 210, and 80. The range has five cells, but only four of them contain a value.
=SUM(B2:B6)This formula returns 505. Excel does not stop at the blank cell. The range is read as a whole block, and the function decides what to do with each cell inside it. For SUM, a blank cell contributes nothing.
How a function reads a range
When you pass a range to a function, Excel does not copy the numbers into the formula. The formula stores a reference, a pointer to the location. Each time the worksheet recalculates, the function reads the current contents of every cell the reference covers.
That is why a formula updates when you change an input. Editing B4 from blank to 150 makes =SUM(B2:B6) return 655 without any change to the formula.
The order matters. The function reads stored values first, and its own rules decide which of them count. A function never changes the cells it reads.
Ranges that grow and shrink
References adjust when you change the worksheet structure. This is mostly helpful, but it has edge cases you should know.
- Inserting a row inside the range expands it. If you insert a row between rows 3 and 4,
B2:B6becomesB2:B7and includes the new cell. - Inserting a row after the last row does not expand the range. A new value typed in
B7is outsideB2:B6and is not counted. - Deleting a row inside the range shrinks it.
B2:B6becomesB2:B5. - Deleting every cell the reference covers produces a
#REF!error, because the reference no longer points anywhere.
The second point is the one that catches people. A total at the bottom of a growing list silently misses new rows added below the range. Solutions include whole-column references, which are covered in a later chapter, or Excel tables, which expand automatically.
Beyond a single block
A function argument can be more than one contiguous block. There are three common forms.
First, a function can accept several arguments separated by commas. Each argument is its own reference or value:
=SUM(B2:B3, B5:B6)This adds B2:B3 and B5:B6 and skips B4. It returns 505. Separating the blocks with a comma is the standard way to read non-adjacent cells.
Second, a range can point at another worksheet. Put the sheet name and an exclamation mark before the range:
=SUM(Sheet2!B2:B6)
=SUM('Q1 Sales'!B2:B6)If the sheet name has spaces or punctuation, wrap it in single quotes, as in the second line. A reference can only name one sheet this way. Both ends of the range must be on the same sheet.
Third, you can give a range a name. Select B2:B6, type Sales into the Name Box at the left of the formula bar, and press Enter. Then use it in formulas:
=SUM(Sales)A named range makes formulas easier to read. It behaves exactly like the address it stands for, so the same rules apply.
The intersection operator
A single space between two references is the intersection operator. It returns only the cells the two references have in common:
=SUM(B2:B6 A4:C4)The column block and the row block overlap only at B4, so the formula reads one cell. You will rarely need this. It is worth recognizing, because a space typed by mistake between two references, where you meant a comma, changes the meaning. If you write =SUM(B2:B3 B5:B6), the two blocks share no cells. Excel returns a #NULL! error.
Common mistakes with ranges
- Selecting too little. Dragging to select a range and stopping one row short leaves a value out. Check the range border Excel draws around the cells while you edit the formula.
- Including the total in its own range. If the formula in
B7is=SUM(B2:B7), it refers to itself. Excel shows a circular reference warning. - Including header cells. A range that starts at
B1includes the text header "Sales". For SUM this is harmless. For other functions, such as COUNTA, the header changes the answer. - Trusting the display. Numbers stored as text and rounded displays both look like numbers. The grid is not a reliable guide to what a function will read.
- Mixing up the separator. A comma separates arguments, a colon builds a range, and a space intersects. In some regional settings the argument separator is a semicolon, so use the one your Excel expects.
Key points
- A cell reference identifies a location. A range reference,
first:last, identifies a rectangle of cells. - Functions read stored values, not the formatted display.
- A range is read as a block. Blank cells inside it are part of the range, and each function decides how to treat them.
- Ranges adjust when rows or columns are inserted or deleted inside them, but not when you add data just past the end.
- Comma means "next argument", colon means "range", and space means "intersection".
Exercise
A worksheet has the numbers 10, 20, and 30 in B2, B3, and B4, and B5 is blank. Cell B2 is formatted to show no decimals but actually holds 10.4. What does =SUM(B2:B5) return, how many cells does the range B2:B5 contain, and what happens if you then type 40 in B6?
Show answer
The formula returns 60.4, because SUM uses the stored value 10.4 rather than the displayed 10. The range contains 4 cells, even though one is blank. Typing 40 in B6 changes nothing, because B6 lies outside B2:B5, so the result stays 60.4 until the range is extended to B2:B6.
Exercise
You want to add the values in B2:B3 and B5:B6 but skip B4. Which separator joins the two ranges inside SUM, and what error appears if you use a space instead?
Show answer
Use a comma: =SUM(B2:B3, B5:B6). A space is the intersection operator, and the two blocks have no cells in common, so Excel returns #NULL!.