To match two columns in Excel, use =VLOOKUP(lookup_value, table_array, col_index_num, FALSE) where the lookup value is in one column, the table array covers both columns, and FALSE forces an exact match. For example, =VLOOKUP(A2, $C$2:$D$100, 2, FALSE) returns the value from column D when column C matches A2. This article explains the formula, its limitations, and better alternatives.
What VLOOKUP Does and When to Use It
VLOOKUP searches for a value in the first column of a range and returns a value from a specified column in the same row. It is ideal for pulling data from a lookup table, such as finding a product price based on an ID, or matching employee names to department codes. The function works vertically (top to bottom), hence the “V” in VLOOKUP.
How to Write the Formula for Matching Two Columns
Assume you have a list of names in column A (A2:A10) and a lookup table with names in column C (C2:C10) and corresponding scores in column D (D2:D10). To get the score for each name in column A, enter this formula in B2 and copy down:
=VLOOKUP(A2, $C$2:$D$10, 2, FALSE)
This returns the score from column D when the name in C matches A2. If no match is found, it returns #N/A. The FALSE argument is critical—it tells Excel to look for an exact match, not an approximate one.
Why Use FALSE for Exact Matching
VLOOKUP’s fourth argument, range_lookup, is optional but often misused. If omitted or set to TRUE, Excel performs an approximate match, which requires the first column of the table array to be sorted ascending. For matching two columns where you need exact equality, always use FALSE. Approximate matches can return wrong results silently, especially if your data isn’t sorted.
Common Problems and How to Fix Them
- #N/A errors: Means no exact match found. Check for extra spaces, non-printable characters, or formatting differences (e.g., text vs. number). Use
=TRIM(A2)to clean data. - #REF! error: The column index number exceeds the number of columns in the table array. Ensure the count starts from the first column of the array.
- #VALUE! error: Usually means the lookup value is longer than 255 characters or the table array is not properly defined.
- False matches: If you see a result that seems wrong, check that the first column of the table array is the one you’re matching against. VLOOKUP always looks in the leftmost column.
Alternatives to VLOOKUP for Matching Columns
Excel 2021 and Microsoft 365 offer XLOOKUP, which is more flexible: it can look to the left, return multiple values, and has built-in error handling. For example, =XLOOKUP(A2, C2:C10, D2:D10, "Not found") does the same as the VLOOKUP above but without the column index. Another option is INDEX-MATCH: =INDEX(D2:D10, MATCH(A2, C2:C10, 0)). This works in all Excel versions and allows leftward lookups.
Matching Two Columns to Return a Yes/No or Count
If you only need to know whether a value in column A exists in column B, use =IF(COUNTIF(B:B, A2)>0, "Yes", "No"). For counting how many times a value appears, use =COUNTIF(B:B, A2). These are simpler than VLOOKUP when you don’t need to return another column’s value.
Case Sensitivity and Exact Match Nuances
VLOOKUP is not case-sensitive; it treats “apple” and “APPLE” as the same. If you need case-sensitive matching, use XLOOKUP with the match mode argument set to 0 (exact match) but note that XLOOKUP also ignores case by default. For case-sensitive matching, use EXACT in an array formula or use INDEX-MATCH with EXACT: =INDEX(D2:D10, MATCH(TRUE, EXACT(A2, C2:C10), 0)) (enter as array formula with Ctrl+Shift+Enter in older versions).
Frequently Asked Questions
Why does VLOOKUP return #N/A even though I see the value in the lookup column?
This usually happens due to hidden spaces or non-printable characters. Use =TRIM(A2) on the lookup value and =TRIM(C2) on the lookup column, or use the CLEAN function to remove line breaks. Also check that both columns are formatted as text or as numbers consistently.
Can VLOOKUP match two columns and return multiple matches?
No, VLOOKUP returns only the first match. To return all matches, use the FILTER function (Excel 365): =FILTER(D2:D10, C2:C10=A2). For older versions, use an array formula with INDEX and SMALL.
What is the difference between VLOOKUP and HLOOKUP?
HLOOKUP searches horizontally across the top row of a table, while VLOOKUP searches vertically down the first column. Use HLOOKUP when your lookup values are in a row and you want to return a value from a lower row.
How do I match two columns and highlight matches in Excel?
Use Conditional Formatting. Select the range in column A, go to Home > Conditional Formatting > New Rule > Use a formula, and enter =COUNTIF($B:$B, $A1)>0. Set a format and click OK. This highlights cells in column A that appear in column B.
Does VLOOKUP work in Google Sheets?
Yes, VLOOKUP works the same way in Google Sheets, but Google Sheets also has XLOOKUP (as of 2022) and QUERY for more advanced matching. The syntax is identical, but the argument separator is a comma in both.
Can I use VLOOKUP to match two columns and return a value from a third column?
Yes, that’s its primary purpose. Just ensure the lookup column is the first column in the table array, and set the column index to the column number you want to return. For example, to return column E when matching columns A and C, use =VLOOKUP(A2, $C$2:$E$100, 3, FALSE).
Related
- Split CSV File with Bash: 5 Real Methods
- Number 5 Battery Equivalent: What It Is and How to Replace It
- PL/SQL Queries for Interview: 20+ Real Questions
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Calculate Profit Margin % in Excel: Formula and StepsTo calculate profit margin in Excel, divide profit by revenue. With revenue in B2 and total costs in…
- Wedding Budget Spreadsheet: Sample, Formulas & SetupA useful wedding budget spreadsheet lists each expense, the amount set aside, the latest estimate, the contracted or…
- Calculate Hours in Excel: Formulas and Time FormatsTo calculate elapsed hours in Excel, put the start time in A2 and end time in B2, then…
- Excel Date Minus Date in Years? DATEDIF ExplainedThe direct answer: use =DATEDIF(start_date, end_date, "Y") to get whole years between two dates in Excel. For example,…
- PV Formula in Excel: How to Use ItThe PV function in Excel calculates the present value of a loan or investment based on a constant…
- Excel Average Days Between Multiple Dates: Formulas and TipsWith dates in chronological order in A2:A6, calculate each gap in a helper column and average those gaps:…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.