Spreadsheet & Formula Studio

Fix #REF! in Excel VLOOKUP: Causes and Fixes

Why VLOOKUP returns #REF!: a column number past the table or a deleted reference, and how to correct the range or the formula.

PerkTonic Team3 min read
Cover of the guide "Fix #REF! in Excel VLOOKUP: Causes and Fixes"

VLOOKUP shows #REF! for one of two reasons: the column number is larger than the number of columns in the table, or a deleted column, row or sheet left a literal #REF! inside the formula. Paste the formula into the Excel Formula Debugger and it checks both. The fix is to widen the table range, correct the column number, or restore the reference that was deleted.

Why VLOOKUP returns #REF!

VLOOKUP takes a table range and a column number, counted from the first column of that range, not from column A of the sheet. If the number is higher than the number of columns in the range, the function has nothing to return and gives #REF!.

The second cause is an edit. When you delete cells that a formula points to, Excel replaces the reference with #REF! inside the formula text. The formula then reads like =VLOOKUP(A2,#REF!,4,FALSE) and cannot work until the reference is rebuilt.

A typical case: the formula asks for column 4 of a 3-column table. For example, =VLOOKUP(A2,Products!A2:C200,4) points at three columns (A to C) but asks for the fourth.

Steps to fix it

  1. Open the Excel Formula Debugger.
  2. Paste the formula, for example =VLOOKUP(A2,Products!A2:C200,4).
  3. Pick #REF! as the error.
  4. Read the Likely causes.
Excel Formula Debugger listing a High confidence cause for a VLOOKUP #REF! error with column 4 in a 3-column table
The debugger flags that column 4 is requested from a table with 3 columns.

The rules find a literal #REF! in the formula and column numbers past the table. For this formula the column number is the cause: 4 is past a table that has 3 columns. The result is listed with a High confidence badge, because the formula alone is enough to show it.

If you are not sure which column holds the value, describe it in the data description, for example "prices are in column D", and use Ask the AI. In this example the fix is:

=VLOOKUP(A2,Products!A2:D200,4,FALSE)

The assumptions listed with the fix are that the prices are in column D and that the codes are unique. Check both against your sheet, then test the formula on a copy of your data.

Ask the AI result in the Excel Formula Debugger with the corrected VLOOKUP formula and its assumptions boxed
The fix widens the table to column D and lists its assumptions: prices in column D, codes unique.

A literal #REF! left in the formula

When the formula text itself contains #REF!, the range was deleted. Press Ctrl+Z straight after the deletion if you can, because that restores the original reference. If the file was saved and closed, retype the range:

  • Click the cell and select the #REF! part in the formula bar.
  • Replace it with the table range, for example Products!A2:D200.
  • Check the column number against the restored range, and add FALSE as the fourth argument for an exact match.

If a whole sheet was deleted, the formula cannot be repaired from the formula bar. Recreate the sheet with the same name, or point the formula at the sheet that now holds the table. For the other error this function commonly gives, see Fix #N/A in Excel VLOOKUP: Causes and Fixes.

Stop counting columns with XLOOKUP

A column number breaks whenever columns are inserted or removed in the table. XLOOKUP avoids that by taking the return column as a range instead of a number:

=XLOOKUP(A2,Products!A2:A200,Products!D2:D200)

If the price column moves, the reference moves with it. The XLOOKUP vs INDEX-MATCH Generator converts an existing VLOOKUP, and the return column replaces the column number in the result.

XLOOKUP vs INDEX-MATCH Generator showing a VLOOKUP converted, with the return column range marked
In the converted formula, a return column range replaces the column number.

For the differences between the two replacements, read XLOOKUP vs INDEX/MATCH: Which One to Use, and for the conversion itself Convert VLOOKUP to XLOOKUP Without Rewriting It.

Common errors

  • The column number counts from the sheet: with a table in B2:E200, the third column is D, so the number is 3, not 4.
  • The table range was not widened after a column was added on the right, so the new column is past the range.
  • The column number is 0 or negative: VLOOKUP returns #VALUE! instead of #REF!, so a different cause applies.
  • The fourth argument is missing: the formula runs as an approximate match and may return #N/A, which is a separate problem.
  • A formula was copied from another workbook that pointed to a sheet that does not exist here.

Microsoft documents both topics. See How to correct a #REF! error and VLOOKUP function.

Check your own file

Open the Excel Formula Debugger, paste the VLOOKUP that shows #REF! and pick #REF!. Compare the column number with the width of the table range, and rebuild any range that shows #REF! in the formula bar.

Was this guide helpful?
Share

Comments