Sub topic 8
Copying a formula: relative and absolute references
This chapter assumes you can already write a formula such as =B2*C2, and that you know the operator precedence rules from the earlier chapters. Here you will learn what Excel does to a formula's cell references when you copy it. You will also learn how to stop references from moving when they should stay put.
Why copying changes a formula
Most worksheets apply one calculation to many rows. You rarely type the same formula 500 times. You write it once and copy it down. For this to work, Excel does not copy the formula as literal text. It copies the formula's meaning.
When you type =B2*C2 in cell D2, Excel does not store "multiply B2 by C2". It stores a position relative to the formula's own cell: "multiply the cell two columns to my left by the cell one column to my left, in my own row". When you copy that formula to D3, Excel replays the same relative instruction from the new location. The result is =B3*C3.
A reference that behaves this way is a relative reference. It is the default for every reference you type, including B2, C2 and F1.
A reference that keeps pointing at the same cell wherever the formula goes is an absolute reference. You make a reference absolute by putting a dollar sign $ in front of the column letter, the row number, or both. A $ in front of one part locks that part. This is a reference marker, not a currency symbol.
A worked example
Build this sheet. Row 1 holds the headings, and F1 holds the tax rate 8% (type 8%, or 0.08 and apply the Percent format). The label in G1 is only a note.
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | Item | Unit price | Quantity | Line total | Price with tax | 8% | Tax rate (input) |
| 2 | Pen | 2.00 | 10 | ||||
| 3 | Notebook | 4.50 | 3 | ||||
| 4 | Stapler | 12.00 | 1 | ||||
| 5 | Tape | 3.25 | 4 |
In D2, enter the line total:
=B2*C2In E2, enter the price including tax:
=B2*(1+$F$1)Now select D2:E2 and copy both formulas down to row 5. The formulas in row 3 become:
=B3*C3
=B3*(1+$F$1)Look at what moved and what stayed. B2 became B3 because it is relative, so it follows the row. $F$1 stayed $F$1 because both its column and its row are locked. Every row now reads its own price and quantity, but all rows read the same tax rate.
The results are:
| Item | Line total (D) | Price with tax (E) |
|---|---|---|
| Pen | 20 | 2.16 |
| Notebook | 13.5 | 4.86 |
| Stapler | 12 | 12.96 |
| Tape | 13 | 3.51 |
The reward is that you can change F1 to 10% and all four tax results update at once. Nothing in the formulas needs editing.
Ways to copy a formula
All of these use the same relative-reference rules.
- Fill handle. Select the cell, then drag the small square at its bottom-right corner down or across. This is the quickest method for adjacent cells.
- Double-click the fill handle. Excel fills down as far as the neighboring column has data. It stops at the first blank cell in that neighbor column, so a gap in your data ends the fill early.
- Ctrl+D fills the top cell of a selection down through the selected range. Ctrl+R fills the left cell to the right.
- Ctrl+C then Ctrl+V. Copy the cell, select the destination (one cell or a range), and paste. Use this when the destination is not adjacent.
On a Mac, use Cmd in place of Ctrl for copy and paste. Check your version's menu for the fill shortcuts.
A fill or paste also copies the cell's number format and borders. After a fill, the Auto Fill Options button appears near the corner of the filled area. Choose Fill Without Formatting from it if you want only the formulas.
What goes wrong when you forget the dollar signs
Suppose you write the tax formula without locking the rate:
=B2*(1+F1)In row 2 this works, because F1 is the right cell. Copy it down and the relative F1 moves with the formula:
| Cell | Formula after copying | Result |
|---|---|---|
| E2 | `=B2*(1+F1)` | 2.16 |
| E3 | `=B3*(1+F2)` | 4.5 |
| E4 | `=B4*(1+F3)` | 12 |
| E5 | `=B5*(1+F4)` | 3.25 |
Here F2, F3 and F4 are empty. Excel treats an empty cell as 0 in arithmetic, so each formula calculates price * (1 + 0) and returns the price without tax. There is no error message. The first row looks right and the others are quietly wrong.
This is the most common copying bug. A formula that is correct in its first cell but wrong after a fill almost always has a reference that should have been absolute.
Absolute references and the F4 key
You can type the dollar signs yourself, but there is a shortcut. While you are editing a formula, place the cursor on or next to a reference and press F4 (on Windows). Each press moves the reference to the next form:
F1is fully relative.$F$1locks the column and the row.F$1locks only the row.$F1locks only the column.- The next press returns to
F1.
On a laptop you may need to hold Fn while pressing F4. On Excel for Mac, Cmd+T performs the same cycle.
Mixed references
The forms F$1 and $F1 are mixed references. One part is locked and the other is relative. They matter when one formula must be copied both down and across, and each direction needs different behavior.
The classic case is a multiplication table. Put the numbers 1, 2 and 3 in B1:D1 and in A2:A4. In B2, enter:
=$A2*B$1Read each half separately.
$A2locks the column. When you copy across, it keeps reading column A. The row is relative, so copying down moves it to$A3,$A4.B$1locks the row. When you copy down, it keeps reading row 1. The column is relative, so copying across moves it toC$1,D$1.
Copy B2 to the whole block B2:D4. The formula in C3, for example, becomes:
=$A3*C$1That is row 3's number from column A times column C's number from row 1. The finished table is:
| Row | 1 | 2 | 3 |
|---|---|---|---|
| 1 | 1 | 2 | 3 |
| 2 | 2 | 4 | 6 |
| 3 | 3 | 6 | 9 |
If you had used fully absolute $A$2*$B$1, every cell would repeat the same product. If you had used fully relative A2*B1, the references would drift diagonally and most cells would be wrong. Mixed references are what make one formula do the work of nine.
Choosing the right reference type
Decide for each reference in a formula by asking how it should behave when copied. Do this one reference at a time, not once for the whole formula.
In practice:
- Values that belong to the row, such as the price and quantity in a line item, are relative.
- Single inputs that every row shares, such as a tax rate, a discount or an exchange rate, are absolute.
- Row headings and column headings in a grid calculation are mixed.
A good habit is to put shared inputs in their own labeled cells instead of typing them into formulas. The formula =B2*(1+$F$1) is easier to audit and change than =B2*1.08, which hides the rate inside the formula.
Copy versus move
Copying and moving (cutting) are different operations, and they treat references differently.
- Copy (Ctrl+C, Ctrl+V, fill handle) adjusts relative references in the new formula, as described above.
- Cut and paste (Ctrl+X, Ctrl+V, or dragging a cell by its border) moves the formula unchanged. Its references still point to the same cells as before, even if they were relative.
If you cut D2 and paste it into H2, the formula is still =B2*C2. Use cut when you want the same calculation in a different place. Use copy when you want the same pattern applied to different data.
Cut has a second effect on the cell you move. Any other formula that referred to the moved cell is updated to follow it. Copying does not do this, because the original cell stays where it was.
Edge cases and errors from copying
Copying past the edge of the sheet
A relative reference can be pushed off the sheet. Suppose B2 contains:
=A1*2Copy B2 to A2. The formula needs "one column left" of column A, which does not exist. Excel shows #REF!, the error for an invalid reference. The same happens copying upward from row 1. Check the direction you copy when a formula refers to cells above or to the left of itself.
Division by zero or empty cells
Take the division formula from earlier in this tutorial:
=A2/B2Copy it down a column where some cells in B are 0 or empty, and those rows return #DIV/0!. This is not a copying fault. The copy simply applies the formula to rows where the divisor is unusable. Fix the data in column B, or handle it in the formula with a later technique such as IF.
Text in a copied reference
A copied formula can land on a cell that holds text. If =B2*C2 is copied to a row where C holds the word "none", the result is #VALUE!, because Excel cannot multiply text. A number stored as text, such as a quantity imported with a leading apostrophe, causes the same problem.
A formula that never changes after you fill it
If you fill a formula down and every cell shows the same value as the first, the fill may be correct but the workbook may not be recalculating. Check Formulas > Calculation Options and make sure it is set to Automatic.
Locked in the wrong place
Locking too much is as harmful as locking too little. If you write =$B$2*$C$2 in D2 and copy it down, every row repeats the row 2 result. When copied results look identical, check for unneeded $ signs.
Checking a copied formula
You do not need to read every row. Spot-check with these tools.
- Press F2 on a formula cell. Excel enters edit mode and outlines each referenced cell in a color that matches the reference in the formula text. Check that the outlines sit on the cells you expect. Press Esc to leave without changing anything.
- Show all formulas with Ctrl+
(the backtick key, usually above Tab). Every cell displays its formula text instead of its result. Press it again to switch back. In a filled column you can scan the row numbers and see whether they step as expected, and whether$F$1` is identical in every row. - Check the last row as well as the first. A reference that has drifted is easiest to see at the far end of the fill.
- Calculate one row by hand. For row 3, compute 4.50 × 1.08 = 4.86 and compare it with E3.
Summary of reference types
| Written as | Type | Column when copied across | Row when copied down |
|---|---|---|---|
| `B2` | Relative | Changes | Changes |
| `$B$2` | Absolute | Fixed | Fixed |
| `B$2` | Mixed, row locked | Changes | Fixed |
| `$B2` | Mixed, column locked | Fixed | Changes |
Exercises
Exercise
In D2 you enter =B2*C2 and then fill it down to D3. What formula does D3 contain, and why?
Show answer
D3 contains =B3*C3. Excel stores the references as positions relative to the formula's cell (two columns left and one column left, same row). Copying the formula one row down moves both references down one row.
Exercise
A sheet has a discount rate in H1 and prices in B2:B20. You write =B2*(1-H1) in C2 and fill it down. C2 is correct, but C3 and below equal the price with no discount. What went wrong, and what is the corrected formula for C2?
Show answer
H1 is relative, so in C3 it became H2, which is empty and counts as 0. The corrected formula is =B2*(1-$H$1), which keeps pointing at H1 in every row.
Exercise
You enter =$A2*B$1 in B2 and copy it to C3. What formula does C3 contain?
Show answer
=$A3*C$1. The column A and row 1 are locked by the dollar signs. The row in $A2 moves down one row and the column in B$1 moves right one column.
Exercise
The formula =A1*2 is in B2. You copy it to A2 and see #REF!. Why?
Show answer
The relative reference means "one column to the left and one row up". From column A there is no column to the left, so the reference is invalid and Excel returns #REF!.
Exercise
You cut D2 (containing =B2*C2) and paste it into H2. What formula is in H2, and how does this differ from copying?
Show answer
H2 still contains =B2*C2. Cut and paste moves a formula without adjusting its references, while copy and paste adjusts relative references to the new location.