Excel Lookup Functions: VLOOKUP, HLOOKUP, and XLOOKUP
In this article
To perform a "look function" in Excel, you use lookup formulas—most commonly VLOOKUP or XLOOKUP—to search for a specific value in one column and return a corresponding value from another column in the same row. These functions automate the process of connecting two different sets of data, such as finding a customer's email address using their unique Order ID without manually scrolling through thousands of rows.
What You'll Need
- Microsoft Excel (installed on Windows, macOS, or accessed via the web).
- A dataset containing a "lookup value" (the unique identifier you are searching for).
- A source table or range where the data is stored, ensuring the lookup value exists in the leftmost column (for VLOOKUP) or anywhere in the range (for XLOOKUP).
Step-by-Step
Depending on your version of Excel, you have different options. XLOOKUP is the modern standard for Microsoft 365 users, while VLOOKUP remains the most widely used for compatibility across older versions. Below are the steps for both.
Using XLOOKUP (Recommended for Microsoft 365)
- Identify your lookup value: Click on the cell that contains the value you want to search for (e.g., cell A2 containing an Employee ID).
- Start the formula: In the cell where you want the result to appear, type
=XLOOKUP(. - Select the lookup value: Click the cell containing the search term (e.g., A2) and type a comma.
- Select the lookup array: Highlight the column or range where the search term is located. For example, if your Employee IDs are in column G of a different sheet, highlight G2:G100. Type a comma.
- Select the return array: Highlight the column or range that contains the information you want to retrieve. If you want the Employee Name from column H, highlight H2:H100.
- Close the formula: Type a closing parenthesis
)and press Enter. The formula looks like this:=XLOOKUP(A2, G2:G100, H2:H100).
Using VLOOKUP (Standard for all Excel versions)
- Identify your lookup value: Ensure you have a cell with the value you are searching for.
- Start the formula: In the target cell, type
=VLOOKUP(. - Select the lookup value: Click the cell containing the search term and type a comma.
- Select the table array: Highlight the entire range of data that includes both the lookup column and the result column. Crucial: The lookup value must be in the very first column of this selection. Type a comma.
- Enter the column index number: Count the columns from left to right within your selected range. If your lookup value is in column 1 and the data you want is in column 3, type
3. Type a comma. - Specify the match type: Type
FALSEto ensure Excel looks for an exact match. Using TRUE may return the closest match, which is often incorrect for IDs or names. - Close the formula: Type a closing parenthesis
)and press Enter. Example:=VLOOKUP(A2, D2:F100, 3, FALSE).
Using HLOOKUP (For Horizontal Data)
- Identify horizontal data: Use HLOOKUP only if your data is arranged in rows rather than columns (headers are on the left, and data flows to the right).
- Start the formula: Type
=HLOOKUP(. - Select the lookup value: Click the cell you are searching for and type a comma.
- Select the table array: Highlight the range of rows. The search value must be in the top row of this selection. Type a comma.
- Enter the row index number: Count the rows down from the top. If the data you want is in the second row of your selection, type
2. Type a comma. - Specify the match type: Type
FALSEfor an exact match. - Close the formula: Type
)and press Enter.
Common Mistakes
The most frequent error in lookup functions is the Column Index Error in VLOOKUP. Users often count the column number based on the entire spreadsheet (e.g., Column C is 3) rather than the selected range. If your range starts at Column D, then Column D is index 1, Column E is 2, and so on.
Another common mistake is omitting the FALSE argument in VLOOKUP. By default, VLOOKUP assumes a TRUE (approximate) match. If your data is not sorted in ascending order, an approximate match will return the wrong value or an error, leading to significant data inaccuracies.
Users also frequently forget to lock their ranges. When you drag a formula down a column, Excel automatically shifts the range references (e.g., A2:B10 becomes A3:B11). To prevent this, use absolute references by adding dollar signs to the range (e.g., $A$2:$B$10) or by selecting the range and pressing F4 on your keyboard.
Tips
To make your spreadsheets more professional and less prone to errors, wrap your lookup functions in an IFERROR function. Instead of seeing an ugly #N/A when a value isn't found, you can display a custom message. For example: =IFERROR(VLOOKUP(A2, D2:F100, 3, FALSE), "Not Found").
For very large datasets, consider converting your data range into an Excel Table (Select data > Ctrl+T). When you use a Table, you can use "Structured References" (like [EmployeeID]) instead of cell ranges. This means that as you add new rows to your table, the lookup formulas will automatically include the new data without you having to update the range manually.
If you are working with data that requires searching from right to left (where the result is to the left of the lookup value), VLOOKUP cannot do this. In these cases, use XLOOKUP or a combination of INDEX and MATCH. INDEX returns a value from a specific position, and MATCH finds that position, allowing for total flexibility in where your columns are located.
Troubleshooting
If your formula returns #N/A, it means Excel cannot find the lookup value. First, check for leading or trailing spaces in your cells. A cell containing "Apple " (with a space) will not match a cell containing "Apple". You can fix this by using the =TRIM() function to clean your data.
Next, verify data type consistency. If your lookup value is stored as text but the source table stores it as a number, Excel will not recognize them as a match. You can tell if a number is stored as text if there is a small green triangle in the corner of the cell. Select the cells, click the warning icon, and choose "Convert to Number".
If the formula returns the wrong value, double-check your column index number in VLOOKUP. Ensure you are counting from the leftmost column of your selected range, not the whole sheet. If you are using VLOOKUP, ensure the final argument is set to FALSE.
If you see a #REF! error, it usually means your column index number is larger than the number of columns in your selected range. For example, if you selected a range of 2 columns but told Excel to return data from column 3, it will trigger this error.
Frequently Asked Questions
Can VLOOKUP search for multiple criteria?
Standard VLOOKUP only searches for one value. To search using multiple criteria, you can create a "helper column" that concatenates the criteria into one string (e.g., =A2&B2) and search for that combined string.
What is the difference between VLOOKUP and XLOOKUP?
VLOOKUP only searches from left to right and requires a column index number. XLOOKUP can search in any direction, does not require an index number, and defaults to an exact match, making it more robust and easier to use.
Why is my VLOOKUP slowing down my computer?
VLOOKUP can be resource-intensive on massive datasets. To improve performance, ensure your data is sorted and use TRUE for approximate matches if applicable, or switch to the INDEX and MATCH combination, which is generally faster.
Does HLOOKUP work the same as VLOOKUP?
Yes, but it is designed for horizontal data. While VLOOKUP searches vertically (down a column), HLOOKUP searches horizontally (across a row) and returns a value from a specified row below the top row.
Can I look up data from a different Excel file?
Yes. When selecting your table array, you can click over to another open workbook and highlight the range there. Excel will automatically include the file path in the formula. Note that if the source file is moved or renamed, the formula may break.