Sub topic 11
Troubleshooting wrong results after copying
This chapter assumes you can enter formulas in Google Sheets, read addresses such as B2, and use the $ sign to build relative, absolute, and mixed references. Here you will learn to find out why a copied formula gives a wrong answer and how to fix it.
Reference errors are hard to spot because the sheet rarely shows an error message. A formula with a drifting reference usually returns a number, and the number is wrong. Your job is to check that each copied formula still points where you meant it to.
Why copied formulas go wrong
When you copy a formula, Google Sheets does not copy the text. It copies the offset from the formula cell to each reference. A relative reference such as E1 means "the cell 5 columns to the right and 1 row up from here." When the formula moves one row down, the offset stays the same, so the reference now points one row lower.
A wrong result after copying has one of four causes:
- A reference that should be locked is relative, so it drifts.
- A reference that should move is locked, so every row returns the same answer.
- A mixed reference locks the wrong half, the row instead of the column or the reverse.
- A range was locked in the wrong places, or not locked at all, so it slides off your data.
The first step is to work out which of the four you have.
A diagnostic routine
Use the same steps every time. They take under a minute and work on any sheet.
- Compare the wrong cell with the first cell. If the first row is right and later rows are wrong, the formula was probably fine at the start and broke when it was copied.
- Click a wrong cell and read its formula in the formula bar. Compare it with the formula you filled from.
- Look at the highlighted cells. When you press
F2or double-click a cell to edit it, Sheets colors each reference and outlines the matching cell or range. A colored box sitting on an empty cell is a sign of drift. - Decide what each reference should do when copied. Ask whether it should move with the row, move with the column, or stay put.
- Fix the first cell, then fill again over the whole range. Do not patch cells one by one.
You can also display every formula at once with View > Show formulas (the shortcut is Ctrl+~ on Windows and Chrome OS, and Cmd+~ on Mac). This makes the pattern visible, because you can read down a column and see where the references change.
Symptom 1: the tax rate drifts to an empty cell
This is the most common mistake. The rate sits in E1, and the formula refers to it without $:
Cell B2: =A2*E1
Cell B3 (after fill down): =A3*E2B2 is correct because E1 holds the rate. In B3 the reference has become E2, which is empty. Sheets treats an empty cell as 0 in arithmetic, so B3 returns 0. Every row below it returns 0 as well.
The pattern to watch for is a correct first row followed by zeros. Edit B2 so the rate is locked, then fill down again:
Cell B2: =A2*$E$1
Cell B3 (after fill down): =A3*$E$1If the cells below the rate hold other numbers, the symptom is worse. Suppose E2 contained a discount percentage. Then B3 would multiply by the discount, and the result would be a believable but wrong number. A zero is easy to notice. A plausible wrong value can sit in a report for months.
Symptom 2: every row shows the same answer
The opposite fault is over-locking. Suppose you lock the price as well:
Cell B2: =$A$2*$E$1
Cell B3 (after fill down): =$A$2*$E$1Every row now multiplies the price in A2, so the whole column shows the same number. If a column of results repeats one value and the inputs differ, look for $ signs on the reference that should have moved.
The fix is to remove the $ signs from the price so it stays relative:
Cell B2: =A2*$E$1Symptom 3: the wrong half of a mixed reference is locked
Mixed references lock only the row or only the column. The $ goes directly before the part that is locked. In the multiplication table, the row headers are in column A and the column headers are in row 1.
| Formula in B2 | What is locked | Result when filled over B2:E5 |
|---|---|---|
| `=$A2*B$1` | Column A and row 1 | Correct table |
| `=A$2*$B1` | Row 2 and column B | Reads the wrong headers and returns incorrect or zero values |
| `=$A$2*$B$1` | Everything | Every cell shows the same product |
| `=A2*B1` | Nothing | The headers slide away from their cells, so the table is wrong |
To check a mixed reference, say it aloud: "$A2 keeps the column A and lets the row change." The $ is a lock on whatever follows it. In $A2 it locks A. In B$1 it locks 1.
When you fill across, columns change, so any reference that must hold its column needs $ before the letter. When you fill down, rows change, so any reference that must hold its row needs $ before the number. A table needs both directions, so you need one of each kind.
Symptom 4: ranges that slide away from the data
Functions such as SUMIF, COUNTIF, and VLOOKUP take ranges. A range is two references joined by a colon, and each end can drift on its own. Here is a formula filled down a list of criteria in column D, with the ranges unlocked:
Cell E2: =SUMIF(A2:A100, D2, B2:B100)
Cell E3 (after fill down): =SUMIF(A3:A101, D3, B3:B101)Each row moves the range down by one. Row 2 searches the data from row 2 to row 100. Row 3 skips row 2 and ends at row 101. By row 20 the formula has dropped 18 rows of your data, and the totals are too small. Nothing shows an error.
Lock the ranges and keep the criterion relative:
=SUMIF($A$2:$A$100, D2, $B$2:$B$100)The criterion D2 stays relative on purpose, because each row needs its own criterion.
VLOOKUP and the table range
VLOOKUP has the same fault, and it can also produce #N/A. In this example the lookup table is in G2:H50:
Cell B2: =VLOOKUP(A2, G2:H50, 2, FALSE)
Cell B3 (after fill down): =VLOOKUP(A3, G3:H51, 2, FALSE)The table range shifts down with each row. Soon the lookup value is no longer inside the range, so VLOOKUP returns #N/A. A fixed version is:
=VLOOKUP(A2, $G$2:$H$50, 2, FALSE)The #N/A error here is a clue. If a lookup works for the first few rows and then fails, the table range is moving.
Symptom 5: copying and pasting behaves differently from filling
Dragging the fill handle and copy-and-paste both adjust relative references by the same rule. Two situations still catch people out.
- Cut and paste does not adjust references. When you cut a formula cell and paste it elsewhere, the formula keeps its original references. If you cut a referenced cell, such as the tax rate in
E1, Sheets updates the formulas that point to it. People sometimes expect copy behavior from a cut and are surprised, or the reverse. - Paste values or formulas only. If you copy a formula and paste with Paste special > Values only, the formula is replaced by its current result. The numbers then stop updating when the inputs change. If a sheet shows correct numbers that do not respond to edits, check whether the cells contain formulas at all.
Inserting or deleting rows also affects references. If you delete the row or column that holds a referenced cell, formulas that depended on it show #REF!. This is a different problem from drift. #REF! means the target no longer exists, and you need to restore the cell or rewrite the reference.
Symptom 6: references to other sheets
An absolute reference to another sheet is written Settings!$B$1. The $ signs work the same way, but people often lock only the cell and forget that the sheet name is already fixed. The sheet name never changes when you copy. Only the cell part can drift.
Cell B2: =A2*Settings!B1
Cell B3 (after fill down): =A3*Settings!B2Here Settings!B2 is probably empty, so row 3 returns 0. The fix is the same as before:
=A2*Settings!$B$1A practical checking example
The table below lists a small price sheet in which the rate in E1 is 0.2. The first column shows the prices and the second shows a faulty formula that was filled down.
| Row | Price in A | Formula in B | Value in B | Expected |
|---|---|---|---|---|
| 2 | 10 | `=A2*E1` | 2 | 2 |
| 3 | 20 | `=A3*E2` | 0 | 4 |
| 4 | 30 | `=A4*E3` | 0 | 6 |
The first row is right, and the rest are 0. That pattern points to symptom 1. Change B2 to =A2*$E$1 and fill down again. The column then shows 2, 4, and 6.
A spot check helps you trust a fix. Pick the last row, read its formula, and work out the answer by hand. If one row at each end of the range is right, the rows between them are almost always right too, because they came from the same formula.
Decision flow
The diagram summarizes how to choose a fix from the symptom.
Edge cases
- Text that looks like a number. A rate typed as
20%is stored as 0.2, but a rate imported as the text"0.2"is not a number. Multiplying by it gives#VALUE!in some cases and a wrong result in others. Reference errors are not the only reason a copied formula fails. - Array formulas. A formula wrapped in
ARRAYFORMULAapplies to a whole range from one cell. It does not need filling, so there is no drift to fix. The$rules still apply to the references inside it. - Blank cells that look empty. A cell containing a space is not empty. Sheets treats it as text, which can cause
#VALUE!where you expected 0. - Shared formulas after sorting. Sorting rows that contain formulas with absolute references to cells outside the sorted range keeps those references. Relative references to cells in other rows can shift in unexpected ways. Check the results after a sort.
Keeping errors from returning
- Put every constant, such as a rate, in its own labeled cell. Do not type it inside formulas.
- Press
F4while the cursor is on a reference to cycle throughA1,$A$1,A$1, and$A1. This is faster and less error prone than typing$by hand. - Use Show formulas as a last check before sharing a sheet.
- Consider a named range for any fixed cell that many formulas depend on. The next chapter covers this.
Exercise
In B2 you wrote =SUMIF(A2:A100, D2, B2:B100) and filled it down to B12. The result in B2 is correct, but the result in B12 is too low, and no error appears. What is wrong, and what formula should you put in B2 before filling again?
Show answer
Both ranges are relative, so each row moves them down one row. By row 12 the ranges start at row 12 and skip the data above it. Lock both ranges and keep the criterion relative: =SUMIF($A$2:$A$100, D2, $B$2:$B$100). Then fill down again.
Exercise
A multiplication table uses row headers in A2:A5 and column headers in B1:E1. You entered =A$2*$B1 in B2 and filled it over B2:E5. The table is wrong. Write the correct formula for B2 and say which half of each reference it locks.
Show answer
The correct formula is =$A2*B$1. $A2 locks column A and lets the row change, so each row reads its own row header. B$1 locks row 1 and lets the column change, so each column reads its own column header.