Sub topic 6
Fixing #REF!: deleted or invalid references
This chapter assumes you can enter and edit formulas, read cell references and ranges such as A2 and A2:A10, and use SUM and VLOOKUP. It covers the two main causes of #REF! and how to repair each one.
What #REF! means
A #REF! error means a formula points to a reference that no longer exists or is not valid. Excel cannot find the cell, range, sheet or column the formula asked for, so it returns the error instead of a value.
There are two common causes:
- A cell, row, column or sheet that the formula used was deleted.
- A function asks for something outside the range it was given, such as a column number that is too large.
Cause 1: deleting cells that a formula uses
Suppose C2 contains =A2+B2. If you delete column B, the formula has lost one of its inputs. Excel rewrites it as =A2+#REF! and the cell shows #REF!.
Deleting is different from clearing. Pressing Delete on a cell's contents leaves the cell in place, so the formula still works and treats the empty cell as zero. Deleting the cell, row or column removes the location itself.
Pasting can cause the same problem. If you copy a formula that uses relative references and paste it somewhere that would point above row 1 or left of column A, the reference falls off the sheet and becomes #REF!. Cutting and pasting over a cell that other formulas use can also break them.
How to repair it
- Click the cell with the error and look at the formula bar. Find the
#REF!text inside the formula. - If you just made the deletion, press Ctrl+Z to undo it. This is the cleanest fix.
- If you cannot undo, replace
#REF!with the correct reference. For=A2+#REF!, type the cell that should be there. - Copy the repaired formula down or across if other cells have the same problem. Find and Replace (Ctrl+H) can also replace
#REF!in many formulas at once. Check the results afterward.
Cause 2: a lookup index that is too large
VLOOKUP returns #REF! when its column index number is larger than the number of columns in the lookup range.
=VLOOKUP(E2,A2:B100,3,FALSE)The range A2:B100 has only two columns, so asking for column 3 returns #REF!. Change the index to a column that exists:
=VLOOKUP(E2,A2:B100,2,FALSE)Count columns from the left edge of the lookup range, not from column A of the sheet. If you add columns to the range later, the index does not adjust on its own, so check it again.
Finding every #REF! in a workbook
Use Find (Ctrl+F), type #REF!, set Look in to Formulas, and choose Find All. This lists every formula that contains a broken reference, including ones on other sheets if you set Within to Workbook.
Formulas in other workbooks can also break. If a linked file is moved or a sheet in it is deleted, the link may return #REF!.
Avoiding the error
- Check what depends on a row or column before you delete it. Trace Dependents on the Formulas tab shows which cells use the selected cell.
- Clear contents instead of deleting cells when you only want to remove data.
- Use whole ranges such as
SUM(B2:B10)rather than listing each cell. If you delete a row in the middle of the range, the range shrinks and the formula still works.
Exercise
A formula in D2 reads =VLOOKUP(A2,F2:H50,4,FALSE) and returns #REF!. What is wrong, and what is the largest index number that would work?
Show answer
The lookup range F2:H50 has three columns (F, G, H), so index 4 is outside it. The largest valid index is 3.
Exercise
C2 contained =A2+B2. You delete column B and C2 now shows #REF!. Name two ways to repair it.
Show answer
Undo the deletion with Ctrl+Z, or edit the formula and replace the #REF! text with the correct cell reference.