Excel Lookup Functions: VLOOKUP & XLOOKUP
In this article
The Excel lookup command retrieves a value from a table based on a specific key, such as a product ID or name. You can perform this action using the VLOOKUP function for compatibility with older spreadsheets or the XLOOKUP function for a more modern, flexible approach. No special software is required beyond a standard installation of Microsoft Excel or a compatible spreadsheet tool like Google Sheets, though syntax and menu paths may vary slightly by version.
What You'll Need
- Microsoft Excel or Google Sheets: The application where the data resides. Both support VLOOKUP and XLOOKUP, but XLOOKUP is a newer addition to the Excel desktop application.
- Two Data Sets: One set containing the lookup value (what you know) and another set containing the data you want to retrieve (what you want to find). These datasets should ideally be in adjacent columns or rows within the same sheet for the simplest setup.
- Basic Understanding of Cell References: You should be comfortable selecting cells with your mouse and typing formulas that reference those cells (e.g., typing "A2" instead of the actual value).
Step-by-Step: Using VLOOKUP
This function searches for a value in the first column of a table and returns a value in the same row from a specified column. It is a staple for data analysis but has limitations, such as being unable to look to the left of the reference column.
- Identify Your Data Structure. Ensure your lookup column (the column containing the key you are searching for, like a SKU or Name) is the very first column in your table array. VLOOKUP cannot search the second or third column first.
- Select the Cell for the Result. Click on the empty cell where you want the retrieved value to appear.
- Start the Formula. Type an equals sign (
=) to begin the formula, followed by the function name:VLOOKUP(. - Enter the Lookup Value. Click on the cell that contains the value you want to find (e.g., the specific product name you are looking up). Type a comma (
,) to separate arguments. For example, if your lookup value is in cell A2, your formula currently looks like=VLOOKUP(A2,. - Specify the Table Array. Highlight the entire range of cells that contains your data. This should include the lookup column and the column(s) from which you want to retrieve data. Do not include the header row in the selection. Type a comma to move to the next argument.
- Define the Column Index Number. This is an integer representing the column number from the right side of your highlighted table array. The first column is 1, the second is 2, and so on. If you want to retrieve data from the third column, enter
3. - Choose the Match Type. Type
0(zero) for an exact match. This is the most common setting to prevent errors like "#N/A" when a slight spelling variation exists. Close the parenthesis to finish the formula. The completed formula might look like=VLOOKUP(A2, B2:E100, 3, 0). - Press Enter. Press the Enter key on your keyboard. Excel will calculate the result and display the value from the third column of your table that corresponds to the value in A2.
- Copy for the Rest of the Data. Click the small square (fill handle) in the bottom-right corner of the result cell and drag it down to apply the formula to other rows in your dataset.
Step-by-Step: Using XLOOKUP
The XLOOKUP function is a more powerful successor to VLOOKUP. It can search in any column, search in both directions (up and down), and handles errors more gracefully. It became available in Excel 2021 and Office 365.
- Identify Your Data. Unlike VLOOKUP, XLOOKUP does not require your lookup column to be the very first column. You can search in the middle of your data.
- Select the Result Cell. Click the cell where you want the data to appear.
- Enter the Function. Type
=XLOOKUP(to start the formula. - Enter the Lookup Value. Click the cell containing the value you want to search for. Type a comma to separate it from the next argument.
- Enter the Lookup Array. Highlight the entire column or range of cells that contains the keys you are searching through (e.g., the column of Product Names). Type a comma.
- Enter the Return Array. Highlight the entire column or range of cells that contains the data you want to retrieve (e.g., the column of Prices). This is a key difference from VLOOKUP; you do not need to calculate a column index number here. Type a comma.
- Optional: Provide a Match Mode. You can specify how Excel should handle a match. The default is
0for an exact match (exact same as VLOOKUP). You can use-1for an exact match or the next smallest item. Type, 0if you want an exact match. - Optional: Provide a Search Mode. You can specify how to search the array. The default is
1, which searches from the top down. You can use-1to search from the bottom up. Type, 1if you want the default behavior. - Close the Parenthesis. Type
)and press Enter.
Common Mistakes
Misusing lookup functions is a frequent source of frustration. Identifying these errors early can save hours of troubleshooting.
- Mismatched Data Types. Excel treats text and numbers as different data types. If you are looking up the number
100in a column of text ("100"), the function will return#N/A. Ensure that the lookup value and the lookup array contain the same data type. A common fix is to use theNUMBERVALUEfunction orVALUEfunction to convert text to numbers, or simply reformat the cells to ensure they are consistent. - Hidden Spaces. Invisible spaces can cause a perfect match to fail. For example, looking up
"Apple "(with a trailing space) will not find"Apple". Use theTRIM()function on your data to remove leading, trailing, and double spaces within a cell before performing the lookup. - Incorrect Column Index Number. In VLOOKUP, it is very easy to miscount the columns. Always count from right to left. If your table array starts in column B and ends in column E, and you want to retrieve data from column D, you must use
2, not4. Counting from the right side (E is 1, D is 2) is safer. - Not Locking the Table Array. When you copy a VLOOKUP formula down a column, Excel dynamically adjusts the range. If you have a formula looking at
B2:E100, Excel might change it toB3:E101for the next row. If your data is not large enough to accommodate this shift, the formula will return an error. To fix this, use absolute references by adding dollar signs before the column and row letters:$B$2:$E$100. This ensures the range never moves.
Tips
- Use Named Ranges. Instead of typing
B2:E100every time, select that range and name itProductTablein the "Formulas" tab. Your formula becomes=VLOOKUP(A2, ProductTable, 3, 0), which is much easier to read and maintain. - Sort Your Data. While not strictly required for VLOOKUP with an exact match, sorting your data alphabetically or numerically can improve calculation speed and make the data easier to visualize.
- Use XLOOKUP for Simplicity. When using XLOOKUP, you don't need to worry about the column index number. You simply specify the column you want to return, which reduces the chance of errors significantly.
- Combine with IFERROR. To make your spreadsheets look cleaner, wrap your lookup function in an IFERROR function. This allows you to display a custom message, such as
"Not Found", instead of the default#N/Aerror. For example:=IFERROR(VLOOKUP(A2, B2:E100, 3, 0), "Not Found").
Troubleshooting
If your lookup function is not working as expected, follow these steps to diagnose the problem.
Check for #N/A Errors
An #N/A error means Excel could not find a value that matches your lookup criteria. Before assuming the data is missing, perform these checks:
- Verify the Lookup Value. Ensure the value in the cell you are searching for matches exactly. Check for hidden characters like spaces, dashes, or symbols that might not be visible at a glance.
- Verify the Lookup Array. Ensure that the column you are searching in actually contains the data. It is possible that the header row was accidentally included in the selection, or the column is empty.
- Check for Data Type Mismatches. As mentioned in the "Common Mistakes" section, ensure that your lookup value is a number if the column contains numbers, or text if the column contains text.
- Use the "Find and Select" Feature. Go to the "Home" tab and select "Find & Select" > "Find...". Enter your lookup value there to see if Excel can locate it within the column. This confirms if the data is actually present in the sheet.
Check for #REF! Errors
A #REF! error indicates a reference to a cell that is no longer valid. This usually happens when you delete a column or row that is referenced by your formula.
Check for #VALUE! Errors
A #VALUE! error suggests that the arguments you provided are of the wrong data type. For example, if you try to use a range of cells as the lookup value, you will get this error. Ensure you are selecting a single cell for the lookup value.
Frequently Asked Questions
Can VLOOKUP search to the left?
No. The VLOOKUP function is designed to search the first column of a table and return a value from a column to the right. To retrieve a value from a column to the left, you can use the INDEX and MATCH combination, or simply use XLOOKUP, which has no such restriction.
What is the difference between VLOOKUP and HLOOKUP?
Both functions perform the same task but in different directions. VLOOKUP searches vertically (down columns), while HLOOKUP searches horizontally (across rows). For most modern spreadsheets, VLOOKUP is the more commonly used function because data is typically organized in columns.
Can I use wildcards in a lookup?
Yes. You can use the asterisk (*) for multiple characters and the question mark (?) for a single character in your lookup value. This is useful for finding partial matches, such as looking up *apple* to find any cell containing the word "apple".
Why is my VLOOKUP returning the wrong value?
This is often due to an incorrect column index number or hidden spaces in the data. Double-check that the column index number correctly points to the data you want to retrieve. Also, use the TRIM() function to clean your data of any invisible characters that might be causing a mismatch.
Is XLOOKUP available in all versions of Excel?
No. XLOOKUP is a newer function that is available in Excel 2021 and Microsoft 365 (Office 365). It is not available in older versions like Excel 2016 or 2019. If you are using an older version, you must use VLOOKUP, INDEX/MATCH, or a third-party add-in.