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. You should also know how a formula's references update when you move or copy cells.
What #REF! means
Excel returns #REF! when a formula contains a reference that no longer points to a valid location. The name comes from "reference". The formula text is still there, but one part of it has lost its target.
The error appears in three main situations:
- A cell, row, or column that the formula used was deleted.
- A cell was pasted over a cell that other formulas pointed to.
- A function was asked for a position that does not exist in the range it was given, such as a VLOOKUP column index that is too large.
A fourth, rarer cause is a link to another workbook or sheet that is closed, renamed, or deleted.
Unlike #DIV/0! or #N/A, #REF! usually means the formula itself is broken. Fixing the data will not help. You need to repair the formula.
Cause 1: Deleted cells, rows, or columns
Suppose C2 contains =A2+B2. If you delete column B, Excel cannot keep the reference to B2. The formula becomes:
=A2+#REF!The #REF! is now written into the formula text as a literal piece of it. You can see this by selecting the cell and looking at the formula bar.
Two actions are easy to confuse here:
| Action | What happens to formulas that used the cells |
|---|---|
| Delete the cells, row, or column | References to them become `#REF!` |
| Clear the contents (press Delete on the keyboard) | References stay valid. They read the empty cell as 0 or as blank |
Clearing contents is safe for references. Removing the cells themselves is what breaks them.
One case is more forgiving. If a formula uses a range and you delete cells inside the range, Excel shrinks the range. =SUM(A1:A10) becomes =SUM(A1:A9) after you delete row 5. It returns #REF! only when the whole range is removed, or when an endpoint of a range is deleted in a way Excel cannot adjust.
How to fix it
- Press Ctrl+Z immediately if you just deleted something by mistake. Undo restores the references.
- If you cannot undo, click the cell and read the formula in the formula bar.
- Replace each
#REF!with the correct reference. Type it, or select the cell with the mouse. - Copy the repaired formula down or across where needed.
Undo only works in the current session and only for recent actions. If the workbook was saved and closed after the deletion, the original reference cannot be recovered from Excel. You must rebuild it from what you know about the sheet, or from a backup copy.
Cause 2: Pasting over a referenced cell
Cut and paste moves a cell, and formulas that point to it follow it. Copy and paste behaves differently. If you copy a cell and paste it over a cell that other formulas use, the target cell's old position is overwritten, and relative references in the pasted formula can point to cells outside the sheet.
Here is a common version of this problem. Cell A1 contains =B1. You copy A1 and paste it into a cell one column to the left, which is not possible because there is no column to the left of A. When a copied formula uses relative references and the paste location would shift a reference off the sheet, Excel reports #REF! in the pasted cell.
Relative references shift by the same distance as the paste. A formula in column B that refers to the cell one column left of it, such as =A1, becomes invalid if you paste it into column A, because it would need to point to a column before A.
To avoid this:
- Use cut and paste (Ctrl+X, Ctrl+V) when the cell should move and keep its references to the same targets.
- Use absolute references such as
$A$1when a formula must always point to one fixed cell. - Paste only values (Paste Special, Values) when you do not want the formula to travel.
Cause 3: A lookup column index that is too large
VLOOKUP takes a column index number as its third argument. That number counts columns inside the lookup table, starting at 1. If the number is larger than the number of columns in the table, VLOOKUP returns #REF!.
=VLOOKUP(E2,A2:B100,3,FALSE)The table A2:B100 has two columns. Asking for column 3 is not possible, so the formula returns #REF!. Changing the 3 to a 2 fixes it:
=VLOOKUP(E2,A2:B100,2,FALSE)This error often appears after someone edits the table. If the table originally covered A2:D100 and a later edit changed it to A2:B100, an index of 3 or 4 that used to work now fails. Check the width of the range against the index number.
The same kind of error occurs with other functions that take a position. INDEX returns #REF! when the row or column number is outside the range:
=INDEX(A1:C10,12,1)The range has 10 rows, so row 12 does not exist.
OFFSET returns #REF! when the shifted range would fall off the worksheet, for example by moving above row 1.
A VLOOKUP that finds no match returns #N/A, not #REF!. If you see #REF! from VLOOKUP, look at the column index, not at the lookup value.
Cause 4: Broken links to other sheets and workbooks
A formula can refer to another sheet, as in =Sales!B5. If you delete the sheet named Sales, the formula becomes:
=#REF!B5Excel keeps the cell address, but the sheet part is gone. Replace #REF! with the correct sheet name, or re-create a sheet with the right name. In some cases, fixing the sheet name in the formula is enough.
For links to other workbooks, such as =[Budget.xlsx]Summary!B5, #REF! can appear if the source file no longer has that sheet or cell, or if the link could not be updated. Use Data, then Edit Links, to see which external files the workbook depends on. You can update the source or change it to point to the correct file.
Finding every #REF! in a workbook
In a large workbook, one deleted column can break dozens of formulas. Use Find and Replace to locate them:
- Press Ctrl+F and open the Replace tab if you want to fix text in formulas directly.
- In Find what, type
#REF!. - Set Look in to Formulas, and Within to Workbook.
- Click Find All. The results list shows each cell that contains the error text in its formula.
Setting Look in to Formulas matters. With the default, the search looks at displayed values, and it can also match cells that only show the error as a result. Searching formulas finds the formulas that contain #REF! as part of their text.
You can also use Go To Special (Ctrl+G, then Special, then Formulas, then Errors) to select every cell whose result is an error. That selection includes all error types, not only #REF!, so check each cell's value after you select it.
Do not hide #REF! with IFERROR
IFERROR can replace any error, including #REF!:
=IFERROR(A2+B2,"")If a deleted column caused the error, this formula would show an empty cell, and the sheet would look fine while the totals are wrong. A broken reference is a mistake in the structure of the workbook. It is not an expected outcome of the data. Repair the reference. If you must handle errors, use IFNA for lookups that find nothing, since it leaves #REF! visible.
Preventing #REF! errors
- Before you delete a row, column, or sheet, select the cells and use Formulas, then Trace Dependents, to see whether other formulas use them.
- Clear contents instead of deleting when you only want to empty the cells.
- Use Excel tables for lookup data. A reference such as
Table1[Price]adjusts when the table changes, and it is less likely to leave a stale column index behind. - Use
XLOOKUPorINDEXwithMATCHwhere available. They select the result column by range, so no hard-coded number can fall out of date. - Keep a backup copy before large structural edits.
Exercise
A worksheet has the formula =VLOOKUP(H2,A2:C50,4,FALSE) and it returns #REF!. Explain why, and give one corrected formula that returns the third column of the table.
Show answer
The table array A2:C50 has three columns (A, B, C), and the column index 4 asks for a fourth column that does not exist, so VLOOKUP returns #REF!. The corrected formula is =VLOOKUP(H2,A2:C50,3,FALSE).
Exercise
You delete column B, and a formula that was =A2+B2 now shows #REF!. Wrapping it in IFERROR makes the cell blank. Why is that a poor fix, and what should you do first?
Show answer
IFERROR hides the broken reference, so the total looks fine but silently leaves out the deleted value. First press Ctrl+Z to undo the deletion if possible. Otherwise, edit the formula and replace #REF! with the correct cell reference.