Sub topic 10
Common mistakes and how to debug them
This chapter assumes you can enter and edit formulas, select ranges, and fill formulas down or across with the fill handle or Ctrl+D. It also assumes you know the three reference types from earlier chapters: relative (B2), absolute ($B$2), and mixed ($B2 or B$2). Here you will learn the errors people make with those types, how to recognize each one from its symptoms, and how to find the cause with Excel's built-in tools.
Why reference mistakes are hard to spot
A reference mistake rarely produces an error message. The formula in the first row is usually correct, because you typed it while looking at that row. The mistake appears only after you copy or fill the formula, and the results are numbers that look plausible.
Two facts explain nearly every case:
- When a formula is copied or filled, each relative part of a reference shifts by the same distance as the formula itself. Parts with a
$do not shift. - A reference written wrongly is still a valid reference. Excel has no way to know that you meant to lock the cell.
So debugging means comparing what you intended with what the copied formulas actually say.
Mistake 1: A fixed input left relative
This is the most common error. You have prices in column B and a tax rate in E1, and you write this in D2:
D2: =B2*E1D2 is correct. Fill it down and the formulas become:
D3: =B3*E2
D4: =B4*E3Both references shifted down one row per row. From D3 onward, the formula multiplies by E2, E3, and so on. Those cells are empty, so the results are 0. If those cells held other numbers, the results would be wrong but not zero, which is worse.
The fix is to lock the rate cell:
D2: =B2*$E$1Symptom: the first row is right, and the rest are zero or nonsense.
Mistake 2: Everything locked
After a mistake like the one above, some people put $ on every reference to be safe:
D2: =$B$2*$E$1Fill it down and every row shows the same value as D2, because nothing moves. This is the opposite symptom: all results are identical, and they match the first row.
Only lock what must stay fixed. The row's own input, here B2, should stay relative.
Mistake 3: The wrong half of a mixed reference
Mixed references fail in a quieter way. Suppose you want a multiplication table with row headings in A2:A10 and column headings in B1:J1. The correct formula in B2 is:
B2: =$A2*B$1Common wrong versions are:
| Formula in B2 | What goes wrong |
|---|---|
| `=A2*B1` | Both references shift, so the headings drift away from the table. Row 3 multiplies B3 by C2... and the values are wrong or zero. |
| `=$A$2*$B$1` | Every cell shows the same product. |
| `=A$2*$B1` | The locks are on the wrong parts. Filling right moves the row heading, and filling down moves the column heading. |
A reliable way to choose the lock: ask what happens when you fill across, then what happens when you fill down. For each reference, decide whether the column should change, and whether the row should change. Lock the part that should not change. In $A2, the column is fixed because every column must read the row heading from column A. In B$1, the row is fixed because every row must read the column heading from row 1.
Mistake 4: A percent-of-total with a moving range
To show each item's share of a total, you might write:
C2: =B2/SUM(B2:B10)This works in C2. Fill it down and C3 becomes =B3/SUM(B3:B11). The range slides down, so the total shrinks by one item each row and eventually includes empty cells below the data. The percentages are too large, and they stop adding up to 100%.
The fix is to lock the whole range inside SUM and leave the row's own cell relative:
C2: =B2/SUM($B$2:$B$10)Symptom: the first row is correct, later rows are too high, and the shares do not add to 100%.
Mistake 5: A running total with the wrong anchor
A running total anchors only the start of the range:
C2: =SUM($B$2:B2)
C3: =SUM($B$2:B3)Two variations go wrong:
=SUM(B2:B2)with no anchor: filled down, the range stays one cell tall, so each row just repeats its own value.=SUM($B$2:$B$2)with both ends anchored: every row repeats the first value.
If the running total does not grow, check which end of the range carries the $. The start is locked and the end moves.
Mistake 6: A lookup table that slides away
Lookup functions take a table range as an argument, and that range is a reference like any other. Consider this formula in B2:
B2: =VLOOKUP(A2,F1:G10,2,FALSE)Fill it down, and B3 searches F2:G11, B4 searches F3:G12, and so on. The row that holds your match slides out of the table, and you start seeing #N/A for items that clearly exist. The first few rows may still work, which makes the problem look random.
The fix is to lock the table:
B2: =VLOOKUP(A2,$F$1:$G$10,2,FALSE)Symptom: #N/A that starts partway down a column, with the first few rows correct.
Mistake 7: Cut and copy treated as the same thing
Copying a formula re-aims its relative references. Cutting and pasting does not. A cut formula keeps pointing at exactly the cells it pointed at before, whether those references are relative or absolute.
Consider C2 containing =A2*B2:
- Copy C2 and paste into E5: the pasted formula is
=C5*D5, because both references shifted by the same distance as the move. - Cut C2 and paste into E5: the formula is still
=A2*B2.
The reverse also matters. If you cut a cell that other formulas refer to, those formulas follow it to its new location. If you copy and paste it, the original stays where it was and the other formulas keep pointing at the original.
This produces two typical mistakes. One is copying a block of formulas when you meant to move it, which leaves old references active and the new copies with shifted references. The other is cutting a block when you wanted shifted references, which leaves formulas pointing at the old inputs.
Mistake 8: Inserting or deleting rows and misjudging the effect
Excel adjusts references when rows or columns are inserted or deleted, but the rules have edges:
- Inserting a row inside a referenced range expands the range.
=SUM(B2:B10)becomes=SUM(B2:B11)if you insert a row between rows 5 and 6. - Inserting a row just below the end of a range does not expand it. If you add a new item under row 10 and the range ends at B10, the new item is not in the total. This is the most common cause of totals that miss the last row.
- Deleting a row that a formula refers to directly gives
#REF!. For example, if you delete row 1 whenD2is=B2*$E$1, the reference toE1is gone, and the formula becomes=B1*#REF!. - Deleting a row inside a range shrinks the range, which is usually what you want.
To make a total absorb new rows, include a blank spacer row at the end of the range, or convert the data to an Excel Table so that ranges grow with the table. Do not rely on typing below the range.
Mistake 9: A typed constant hiding in a formula
Typing the rate directly is not a reference mistake, but it causes the same wrong results later:
D2: =B2*0.2When the rate changes, you must find and edit every formula that contains it, and you will miss some. Put the value in one cell and anchor it, or give the cell a name:
D2: =B2*TaxRateA defined name behaves as an absolute reference, so it does not shift on fill.
Mistake 10: References to another sheet that shift
A reference to another sheet shifts the same way as a reference on the current sheet. This formula is the same trap as in Mistake 1:
C2: =B2*Rates!B1Filled down, C3 reads Rates!B2. The fix is the same:
C2: =B2*Rates!$B$1Keep in mind that the $ goes on the cell part, after the sheet name and the exclamation mark.
A method for debugging
Start from the symptom, not from the formula. The diagram below shows a decision path that covers the mistakes above.
Then confirm the cause with these tools, in roughly this order of effort.
1. Look at the last row, not the first
Click the last filled cell and read its formula in the formula bar. If the mistake is a sliding reference, the problem is plain there: E10 where you expected $E$1, or a range that now ends below your data.
2. Show all formulas at once
Press Ctrl+ (the backtick key, above Tab) to switch the sheet to formula view. Columns of filled formulas should look consistent. A reference that drifts, such as E1, E2, E3` down the column, stands out immediately. Press the same keys again to switch back.
3. Press F2 and read the colors
In edit mode, Excel outlines every referenced cell or range in a color matching the reference in the formula. You see on the sheet which cells the formula reads. If the colored box sits on an empty cell or on the wrong row, you have found the mistake. Press Esc to leave without changing anything.
4. Use Trace Precedents
On the Formulas tab, Trace Precedents draws arrows from the cells a formula reads to the formula. Use it on one wrong cell and check the arrows end where you expect. Remove Arrows clears them.
5. Step through with Evaluate Formula
On the Formulas tab, Evaluate Formula steps through a formula one operation at a time, showing the value of each reference. It is useful for long formulas where several references combine.
6. Compare formulas side by side with FORMULATEXT
FORMULATEXT returns the formula of another cell as text. In a helper column, write:
F2: =FORMULATEXT(D2)
F3: =FORMULATEXT(D3)Fill it down and you get a visible list of each row's formula. Delete the helper column when done.
7. Watch the green triangles
Excel flags cells whose formula differs from their neighbors with a small green triangle and the message "Inconsistent formula". This catches some sliding-reference errors, but not all of them, and it can be switched off. Treat it as a hint, not as a test.
A worked repair
You inherit this sheet. Column A holds items, B holds net prices in B2:B6, and the tax rate 0.2 is in E1. These are the formulas in column C and D:
C2: =B2*E1
D2: =B2/SUM(B2:B6)The sheet shows correct values in row 2 and zeros in C3:C6. The shares in D are too large, and the last one is #DIV/0!.
Diagnosis, using the tools above:
- Click C6. The formula bar shows
=B6*E5. The rate reference slid down onto an empty cell (Mistake 1). - Click D6. It shows
=B6/SUM(B6:B10). The range slid below the data, and the sum is of empty cells, which gives zero (Mistake 4).
Repair, then refill both columns from row 2:
C2: =B2*$E$1
D2: =B2/SUM($B$2:$B$6)Check the result: the shares in column D should add to 100%, and every value in column C should equal the net price times 0.2.
A quick checklist before you fill
- For every reference in the formula, ask: should this move when I fill down? Across?
- Check whether each fixed input is locked: rates, thresholds, lookup tables, totals.
- Check whether each row-specific input is not locked.
- After filling, read the formula in the last cell.
- Check a total, such as shares adding to 100%, as a sanity test.
Exercise
Cell C2 contains =B2*E1, where E1 holds a discount rate. You fill C2 down to C5. C2 is correct, but C3:C5 show 0. What formula in C2 fixes this, and why do C3:C5 show 0?
Show answer
Use =B2*$E$1. When filled down, the relative E1 becomes E2, E3, E4, and so on, which are empty cells, so the product is 0. Locking the reference with $ keeps every row pointing at E1.
Exercise
Column B holds sales in B2:B8. You write C2: =SUM(B2:B2) and fill down, expecting a running total, but each row only shows its own sales value. What single change gives a running total?
Show answer
Anchor the start of the range: C2: =SUM($B$2:B2). The start stays at B2 while the end moves down with each row, so the range grows by one cell per row.
Exercise
A formula =VLOOKUP(A2,F1:G10,2,FALSE) in B2 works for the first rows, but returns #N/A further down although the items exist in the table. What is the cause and the fix?
Show answer
The table range is relative, so it slides down as the formula is filled (B3 searches F2:G11, B4 searches F3:G12, and so on) and eventually excludes the matching row. Lock it: =VLOOKUP(A2,$F$1:$G$10,2,FALSE).
Exercise
You cut C2 (=A2*B2) and paste it into E5. What does the pasted cell contain? What if you had copied instead of cut?
Show answer
After cutting and pasting, E5 still contains =A2B2, because a cut does not re-aim references. After copying and pasting, E5 contains =C5D5, because both relative references shift by the same distance as the formula.