Using VLOOKUP to compare two columns
VLOOKUP is the lookup most people learn first, so it is often the first tool reached for when two columns need comparing. It does the job if two rules are kept: the last argument is FALSE, and the #N/A error is caught. Here is the formula, an example and the cases where VLOOKUP misleads.
Worked example on made-up data
A small example: two lists, the formula our tool produced for them and the result of computing it. The data is invented for the example.
Formula for Excel
=IF(A2="","",IF(ISNA(MATCH(A2,$B$2:$B$6,0)),"missing",""))The formula was verified by computing it on this example (7 rows in the first list, 5 in the second): the result equals the reference answer. The example was also recomputed in LibreOffice Calc with the same result.
MATCH looks for the value of A2 in $B$2:$B$6; if it is not there MATCH returns #N/A, and ISNA turns that into 'not found'. Rows whose value is missing from the second list get "missing". Blank rows of the first list are not flagged. Paste the formula into C2 and fill it down to the end of $A$2:$A$8.
Other verified variants
- VLOOKUP
=IF(A2="","",IF(ISNA(VLOOKUP(A2,$B$2:$B$6,1,FALSE)),"missing","")) - IFERROR + VLOOKUP
=IFERROR(VLOOKUP(A2,$B$2:$B$6,1,FALSE),"missing") - SUMPRODUCT
=IF(A2="","",IF(SUMPRODUCT(($B$2:$B$6=A2)*($B$2:$B$6<>""))=0,"missing","")) - COUNTIF
=IF(A2="","",IF(COUNTIF($B$2:$B$6,A2)=0,"missing",""))
Values of the first list that are not in the second (3)
INV-303, INV-304, INV-306
Compare your own lists
The tool below is already set up for this task. Paste your columns to get a formula for your version and the list, both checked by computing. 3 free comparisons a day, no sign-up.
Formula
Where to paste
Values of A that are not in B:
Please note
How it works
Other formula variants
Free comparisons for today are used up (3 a day)
Your results above stay. Free comparisons come back tomorrow.
Pro for $7/month — coming soon
Pro is coming — leave nothing, we just count interest.
The VLOOKUP formula
VLOOKUP(A2,$B$2:$B$6,1,FALSE) looks for the invoice number in column B and returns the number itself, because the column index is 1. If the number is not there, the result is #N/A; ISNA catches it and IF writes missing. The snapshot above was computed with this VLOOKUP version. The tool's own MATCH formula and the short IFERROR version are shown next to it; all three were checked on the example and agree: INV-303, INV-304 and INV-306 are unpaid.
The short form IFERROR(VLOOKUP(...),"missing") shows the invoice number for found rows and missing for the rest. It is handy when you want to see what was matched, at the cost of a busier column.
Why FALSE matters
Without FALSE (or 0) as the fourth argument, VLOOKUP runs an approximate match. It assumes the column is sorted in ascending order and returns the nearest smaller value. On unsorted invoice numbers that produces matches that do not exist, and the comparison quietly reports paid invoices that were never paid. This is the most common reason a VLOOKUP comparison looks wrong.
Steps
- Click C2, next to the first invoice number.
- Paste the VLOOKUP formula and lock the second range with dollar signs.
- Press Enter and copy the formula down to the last row of the first column.
- Filter column C for missing to see the unpaid invoices.
VLOOKUP or MATCH
For a yes/no check both are equivalent. MATCH is shorter and needs no column index, which is why the tool returns it by default. VLOOKUP pays off when you also want to pull a neighbouring field from the second table, such as the payment date; then the column index is larger than 1.
Common mistakes
Approximate match by default
VLOOKUP(A2,$B$2:$B$6,1) without FALSE silently returns a wrong value on unsorted data. Always add FALSE.
The lookup column must be first
VLOOKUP searches only the leftmost column of the range. If the invoice numbers are in the second column of a table, start the range there or use MATCH.
Wildcards in exact mode
With FALSE, VLOOKUP treats * and ? in the looked-up value as wildcards, just like MATCH. For codes containing them, the tool switches to a SUMPRODUCT comparison.
Questions and answers
FALSE or 0 — is there a difference?
No. Both select an exact match.
Why does VLOOKUP return #N/A when the value is clearly there?
Usually trailing spaces, or a number in one column and the same number stored as text in the other. The tool warns about both when it sees them in your data.
Is XLOOKUP better for this?
XLOOKUP exists only in Excel 2021 and newer (including Excel for the web) and in Google Sheets. The MATCH and VLOOKUP formulas here work in every version from Excel 2010 on.