Sub topic 10
Copying formulas with relative and absolute references
This chapter assumes you can enter formulas, select ranges, and know that a formula starts with =. You should also know what SUM and AVERAGE return. Here you will learn why a copied formula sometimes points at the wrong cells, and how to prevent it.
How Excel stores a reference
When you write =SUM(B2:B6), Excel does not remember the address "B2:B6". It remembers where the range sits relative to the formula cell. If the formula is in B7, the range is "the five cells directly above this one".
When you copy the formula to C7, Excel keeps that relative meaning. The range becomes C2:C6. This is a relative reference, and it is the default.
A reference has two parts, a column letter and a row number. A dollar sign in front of a part locks it.
| Style | Example | Column when copied | Row when copied |
|---|---|---|---|
| Relative | `B2` | Shifts | Shifts |
| Absolute | `$B$2` | Locked | Locked |
| Mixed (column locked) | `$B2` | Locked | Shifts |
| Mixed (row locked) | `B$2` | Shifts | Locked |
When relative is what you want
Suppose columns B, C, and D each hold five monthly figures in rows 2 to 6. You want a total under each column. Write this in B7:
=SUM(B2:B6)Copy B7 to C7 and D7. Each copy totals its own column, because the range shifted with the formula. You wrote one formula and got three correct ones.
When you need absolute
Sometimes every copy must read the same cells. Say B2:B6 holds sales, and you want each copy to show the same grand total, no matter where you paste it:
=SUM($B$2:$B$6)Now the copy in C7, or in H20, still adds B2:B6. Without the dollar signs, the range would slide away and add the wrong cells, or cells that are empty.
A common case is a share of the total. Put the total in B7 and the individual values in B2:B6. In C2, write:
=B2/SUM($B$2:$B$6)Copy it down to C6. B2 is relative, so it becomes B3, B4, and so on. $B$2:$B$6 is locked, so every row divides by the same total. If you forgot the dollar signs, row 3 would divide by SUM(B3:B7), which is a different range and gives a wrong answer with no error message.
Mixed references
A mixed reference locks only one part. This helps when you copy a formula both down and across. Imagine a threshold in A1 and values in a grid. In B3 you could write =IF(B2>$A$1, 1, 0). For a column of names with fixed lookup values you might use $A3, which keeps the column fixed while the row moves.
Switching styles quickly
Click inside a reference in the formula bar and press F4 (on a Mac, Command+T or Fn+F4, depending on your setup). Each press cycles through B2, $B$2, B$2, and $B2.
Common errors
- Totals that are slightly off. A range that should be locked has slid by one or more rows. Click the copied cell and check the range Excel highlights.
- A zero where a total should be. The range has slid onto empty cells. SUM returns 0 for empty cells, and gives no warning.
- A locked reference that should move. If every copy shows the same value, you probably locked too much.
- Cut versus copy. Cutting and pasting a formula does not change its references. Only copying shifts relative ones.
Exercise
In C2 you write =B2/SUM(B2:B6) and copy it down to C3. What formula does C3 contain, and how would you fix the formula in C2 so that copying works?
Show answer
C3 contains =B3/SUM(B3:B7), because both references are relative and shift down one row. Fix C2 by locking the range: =B2/SUM($B$2:$B$6). Then C3 becomes =B3/SUM($B$2:$B$6).
Exercise
A formula in B7 is =SUM(B2:B6). You copy it to D7. What does D7 contain, and which keyboard key helps you add dollar signs while editing a reference?
Show answer
D7 contains =SUM(D2:D6), because the column shifted two to the right. The F4 key cycles a reference through the relative, absolute, and mixed styles.