Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

VLOOKUP with IF: Conditional Lookups in Excel

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You combine VLOOKUP with IF by nesting one inside the other: use IF to test a condition and return one VLOOKUP result when it is true and a different result (or a second VLOOKUP) when it is false. The simplest working pattern is =IF(A2="","",VLOOKUP(A2,Sheet2!A:B,2,FALSE)), which skips blank lookup values and avoids the #N/A error. A second common pattern is =IF(ISNA(VLOOKUP(A2,Sheet2!A:B,2,FALSE)),"Not found",VLOOKUP(A2,Sheet2!A:B,2,FALSE)), which replaces errors with a readable label. Both formulas work in Excel for Microsoft 365, Excel 2021, 2019 and 2016, and the same nesting works in Google Sheets. The exact wording of menus and dialog boxes can differ slightly by version, device and region, but the formula syntax below is stable.

What You'll Need

  • A spreadsheet open in Excel (desktop or web) or Google Sheets.
  • A lookup table with the key in the leftmost column and the value you want to return in a column to its right.
  • The lookup value in the row where you write the formula.
  • Basic familiarity with cell references and the difference between relative and absolute references (the $ sign).

Step-by-Step

  1. Set up your lookup table. Put the unique key (for example, a product code or employee ID) in the first column of the table. VLOOKUP can only search to the right of that column, so the return value must sit in a column to the right. If your data is arranged the other way round, either rearrange it or use INDEX and MATCH instead.
  2. Name the ranges. Decide which sheet and range hold the table. For example, Sheet2!$A$2:$C$100. Use absolute references (with $) so the range does not shift when you copy the formula down.
  3. Write the plain VLOOKUP first. In the cell where you want the result, type =VLOOKUP(A2,Sheet2!$A$2:$C$100,2,FALSE). The FALSE (or 0) at the end forces an exact match, which is what you almost always want with IDs and codes. Press Enter and check that one row returns the expected value.
  4. Wrap it in IF to handle blanks. If the lookup cell can be empty, change the formula to =IF(A2="","",VLOOKUP(A2,Sheet2!$A$2:$C$100,2,FALSE)). Now an empty lookup cell returns an empty string instead of #N/A.
  5. Wrap it in IF to handle missing matches. If the lookup value might not exist in the table, use =IF(ISNA(VLOOKUP(A2,Sheet2!$A$2:$C$100,2,FALSE)),"Not found",VLOOKUP(A2,Sheet2!$A$2:$C$100,2,FALSE)). The inner VLOOKUP runs twice, which is fine for normal-sized tables. In Excel 2013 and later you can use IFERROR instead: =IFERROR(VLOOKUP(A2,Sheet2!$A$2:$C$100,2,FALSE),"Not found"). IFERROR is shorter and also catches other errors, so use it unless you specifically need to distinguish #N/A from other problems.
  6. Use IF to choose between two lookups. When the table to search depends on a condition, nest two VLOOKUPs: =IF(B2="Retail",VLOOKUP(A2,Retail!$A$2:$C$100,2,FALSE),VLOOKUP(A2,Wholesale!$A$2:$C$100,2,FALSE)). Only one VLOOKUP runs per row, so this pattern is efficient.
  7. Use IF to return a calculated value. You can also test the VLOOKUP result itself: =IF(VLOOKUP(A2,Sheet2!$A$2:$C$100,2,FALSE)>100,"High","Low"). This returns a label based on the looked-up number rather than the number itself.
  8. Fill down and verify. Drag the fill handle down the column. Spot-check three or four rows against the source table, including one row that should return "Not found" or a blank. If any result is wrong, check for leading spaces, text stored as numbers, or a range that has shifted.

Common Mistakes

  • Forgetting the fourth argument. Omitting FALSE makes VLOOKUP use approximate match, which returns wrong values on unsorted data. Always type FALSE or 0 for exact match.
  • Relative ranges that shift. If you write A2:C100 without dollar signs and copy the formula down, the range slides down and eventually runs past the table. Use $A$2:$C$100.
  • Mismatched data types. A number stored as text (often shown with a green triangle) will not match a real number. Use VALUE() or TEXT() to convert, or clean the source data.
  • Hidden spaces. Trailing spaces in the lookup column cause #N/A. Use TRIM() on the lookup value: VLOOKUP(TRIM(A2),...).
  • Using IFERROR to hide real problems. Wrapping everything in IFERROR can mask a broken range or a wrong column index. Test the plain VLOOKUP first, then add the error handling.
  • Column index counted wrong. The index counts from the first column of the range you supplied, not from column A of the sheet. If your range starts at column B, the third column of the range is column D.

Tips

  • Prefer IFERROR over IF(ISNA(...)) in modern Excel: it is shorter and easier to read. Use IF(ISNA(...)) only when you need to treat #N/A differently from other errors.
  • Use a named range for the lookup table (Formulas > Define Name) so formulas read like VLOOKUP(A2,PriceList,2,FALSE).
  • If you need to look left, switch to INDEX and MATCH or XLOOKUP, which do not require the key in the first column.
  • Keep the lookup table on its own sheet and avoid inserting columns inside it; inserting a column changes the column index and silently breaks formulas.
  • For large tables, XLOOKUP (available in Microsoft 365 and Excel 2021) is faster and has built-in "if not found" handling, so it can replace the IF wrapper entirely.

Troubleshooting

  • All results show #N/A. Check the lookup value and the first column of the table for type mismatches and spaces. Select a cell in each and compare them with =A2=Sheet2!A2; if it returns FALSE, the values differ even if they look the same.
  • Some rows work, others do not. This usually means the table range does not cover all rows. Extend the range or convert the source to an Excel Table so the range grows automatically.
  • The formula returns the wrong column. Recount the index from the first column of the range, not from column A. If the range starts at B, index 2 returns column C.
  • #REF! appears after copying. The column index is larger than the number of columns in the range, or the range was deleted. Check the range and index.
  • #VALUE! appears. The column index is text or the lookup value is an array where a single value is expected. Make sure the index is a plain number.
  • Results are correct but slow. Whole-column references like A:A on very large sheets slow recalculation. Limit the range to the used rows.

Frequently Asked Questions

Can I use IF and VLOOKUP in the same formula?

Yes. Nest VLOOKUP inside IF, or nest IF inside VLOOKUP's arguments. The most common pattern is =IF(condition, VLOOKUP(...), VLOOKUP(...)) or wrapping VLOOKUP in IFERROR.

What is the difference between IFERROR and IF(ISNA())?

IFERROR catches every error type and returns one fallback value. IF(ISNA()) catches only #N/A, so other errors still show. Use IFERROR for simplicity, and IF(ISNA()) when you want to see other problems.

Why does my VLOOKUP return #N/A when the value clearly exists?

Almost always a data type or whitespace mismatch. Numbers stored as text, trailing spaces, or non-printing characters will prevent a match. Use TRIM() and check with an equality test.

Can I use this in Google Sheets?

Yes. The same VLOOKUP, IF, ISNA and IFERROR functions work in Google Sheets with the same syntax. Google Sheets also has XLOOKUP, but availability depends on your account and region.

Does the order of arguments in VLOOKUP matter?

Yes. The order is lookup value, table range, column index, and match type. Swapping the range and the index produces #VALUE! or a wrong result.

Should I use XLOOKUP instead?

If your version of Excel supports it, XLOOKUP is generally better: it looks in any direction, has a built-in "if not found" argument, and does not need a column index. Use VLOOKUP with IF when you need compatibility with older files or other users' versions.