"Compare these two lists and tell me what's different" is probably the most common task in any office that runs on Excel: system against bank statement, last month's staff list against this month's, your price list against the supplier's. In 17 years in banking I've done it thousands of times, and it always comes down to one of two situations:
- Row by row. The two columns are lined up and you compare each row with the cell next to it.
- List against list. The values can be anywhere, in any order, and you want to know which ones appear in both and which are missing.
They need different formulas. Every example below is a live sheet: click a cell to see its formula, or change the data and watch the result.
1. Compare two columns row by row
When both columns are in the same order, a plain comparison is enough:
=B2=C2
It returns TRUE when the two cells are equal and FALSE when they aren't. Wrap it in IF for a readable result, and subtract the cells to see by how much they differ:
=IF(B2=C2, "Match", "Different")
{"cells": {"A1": "Order", "B1": "System", "C1": "Bank", "D1": "Same?", "E1": "Difference", "A2": "#101", "B2": 250, "C2": 250, "D2": "=IF(B2=C2,\"Match\",\"Different\")", "E2": "=B2-C2", "A3": "#102", "B3": 480, "C3": 408, "D3": "=IF(B3=C3,\"Match\",\"Different\")", "E3": "=B3-C3", "A4": "#103", "B4": 120, "C4": 120, "D4": "=IF(B4=C4,\"Match\",\"Different\")", "E4": "=B4-C4", "A5": "#104", "B5": 75.5, "C5": 75.5, "D5": "=IF(B5=C5,\"Match\",\"Different\")", "E5": "=B5-C5", "A6": "#105", "B6": 310, "C6": 301, "D6": "=IF(B6=C6,\"Match\",\"Different\")", "E6": "=B6-C6"}, "formats": {"B2:C6": {"fmt": "currency"}, "E2:E6": {"fmt": "currency"}}, "focus": "D2", "rows": 7, "note": "Change a bank amount in column C and watch the row flip."}
Order #102 has two digits swapped (480 and 408), the classic typing mistake. The difference column finds it immediately, and a difference divisible by 9 is the tell-tale sign of swapped digits.
Text: upper case, lower case and hidden spaces
With text, two things catch people out. Excel's = ignores case, so Apple equals apple. And a space at the end of a cell, which you can't see, makes two identical-looking values different.
| Formula | What it does |
|---|---|
=A2=B2 |
Compares, ignoring upper/lower case |
=EXACT(A2, B2) |
Compares with case: Apple is not apple |
=TRIM(A2)=TRIM(B2) |
Removes extra spaces first, then compares |
{"cells": {"A1": "List A", "B1": "List B", "C1": "A=B", "D1": "EXACT", "E1": "With TRIM", "A2": "Apple", "B2": "apple", "C2": "=A2=B2", "D2": "=EXACT(A2,B2)", "E2": "=TRIM(A2)=TRIM(B2)", "A3": "Banana", "B3": "Banana", "C3": "=A3=B3", "D3": "=EXACT(A3,B3)", "E3": "=TRIM(A3)=TRIM(B3)", "A4": "Cherry ", "B4": "Cherry", "C4": "=A4=B4", "D4": "=EXACT(A4,B4)", "E4": "=TRIM(A4)=TRIM(B4)", "A5": "Mango", "B5": "Mengo", "C5": "=A5=B5", "D5": "=EXACT(A5,B5)", "E5": "=TRIM(A5)=TRIM(B5)"}, "focus": "C2", "rows": 6, "note": "A4 has an invisible space after “Cherry”. Click it and look at the formula bar."}
Row 4 looks identical in both columns, yet the first two formulas say FALSE. Only the TRIM version sees through the trailing space. If a comparison "should" match and doesn't, a hidden space is the first thing to check.
2. Find which values are in both lists
Now the harder case: two lists in different order. Last month's employees are in column A, this month's in column B. Who left? Who's new?
Comparing row by row is useless here. Instead, for each name ask: how many times does it appear in the other list? That's exactly what COUNTIF answers:
=IF(COUNTIF($B$2:$B$8, A2)>0, "Still here", "Left")
COUNTIF($B$2:$B$8, A2) counts how many cells in column B equal A2. More than zero means the name exists in both lists. The dollar signs lock the list so the formula can be copied down.
To find the new people, turn it around and look for each name of column B inside column A:
=IF(COUNTIF($A$2:$A$8, B2)>0, "", "New")
{"cells": {"A1": "Last month", "B1": "This month", "C1": "Status", "D1": "New?", "A2": "Ana", "B2": "Ben", "C2": "=IF(COUNTIF($B$2:$B$8,A2)>0,\"Still here\",\"Left\")", "D2": "=IF(COUNTIF($A$2:$A$8,B2)>0,\"\",\"New\")", "A3": "Ben", "B3": "Eva", "C3": "=IF(COUNTIF($B$2:$B$8,A3)>0,\"Still here\",\"Left\")", "D3": "=IF(COUNTIF($A$2:$A$8,B3)>0,\"\",\"New\")", "A4": "Cleo", "B4": "Hugo", "C4": "=IF(COUNTIF($B$2:$B$8,A4)>0,\"Still here\",\"Left\")", "D4": "=IF(COUNTIF($A$2:$A$8,B4)>0,\"\",\"New\")", "A5": "Dan", "B5": "Ana", "C5": "=IF(COUNTIF($B$2:$B$8,A5)>0,\"Still here\",\"Left\")", "D5": "=IF(COUNTIF($A$2:$A$8,B5)>0,\"\",\"New\")", "A6": "Eva", "B6": "Gia", "C6": "=IF(COUNTIF($B$2:$B$8,A6)>0,\"Still here\",\"Left\")", "D6": "=IF(COUNTIF($A$2:$A$8,B6)>0,\"\",\"New\")", "A7": "Finn", "B7": "Ida", "C7": "=IF(COUNTIF($B$2:$B$8,A7)>0,\"Still here\",\"Left\")", "D7": "=IF(COUNTIF($A$2:$A$8,B7)>0,\"\",\"New\")", "A8": "Gia", "B8": "Cleo", "C8": "=IF(COUNTIF($B$2:$B$8,A8)>0,\"Still here\",\"Left\")", "D8": "=IF(COUNTIF($A$2:$A$8,B8)>0,\"\",\"New\")", "A10": "In both", "B10": "=SUMPRODUCT(--(COUNTIF(B2:B8,A2:A8)>0))", "A11": "Left", "B11": "=SUMPRODUCT(--(COUNTIF(B2:B8,A2:A8)=0))", "A12": "New", "B12": "=SUMPRODUCT(--(COUNTIF(A2:A8,B2:B8)=0))", "A13": "Who left", "B13": "=TEXTJOIN(\", \",TRUE,IF(COUNTIF(B2:B8,A2:A8)=0,A2:A8,\"\"))"}, "focus": "C2", "rows": 14, "note": "Replace Hugo in B4 with Dan — his status and the counts update."}
Dan and Finn left; Hugo and Ida are new. COUNTIF ignores case, just like =.
Count the matches in one cell
You don't always need a result on every row. Sometimes the question is simply "how many are missing?". Give COUNTIF the whole column as its second argument and it returns a count for every name at once; SUMPRODUCT adds them up:
| Question | Formula |
|---|---|
| How many are in both lists? | =SUMPRODUCT(--(COUNTIF(B2:B8, A2:A8)>0)) |
| How many of A are missing from B? | =SUMPRODUCT(--(COUNTIF(B2:B8, A2:A8)=0)) |
| Which ones are missing? | =TEXTJOIN(", ", TRUE, IF(COUNTIF(B2:B8, A2:A8)=0, A2:A8, "")) |
The double minus -- turns TRUE/FALSE into 1/0 so they can be added. These are array formulas; the cells B10:B13 in the sheet above use them. (TEXTJOIN needs Excel 2019 or newer; in Excel 2019 confirm that formula with Ctrl + Shift + Enter.)
3. Find missing values with MATCH
MATCH is the other classic. It returns the position of a value in a list, or the #N/A error when the value isn't there. ISNA turns that into TRUE/FALSE:
=ISNA(MATCH(A2, $B$2:$B$8, 0))
TRUE means "A2 is missing from column B". The 0 at the end asks for an exact match; never leave it out.
COUNTIF and MATCH give the same answer here. I use COUNTIF because it reads more naturally, and MATCH when I also need to know where the value is.
4. Compare two tables and pull the value across
Often it's not enough to know that an invoice exists in both lists; you need to check that the amount is the same. The two tables are in a different order, so first bring the bank's amount next to the system's, then subtract.
=XLOOKUP(A2, $F$2:$F$6, $G$2:$G$6, "Missing")
XLOOKUP looks for the invoice number in the bank's list and returns the amount from the column next to it. If the invoice isn't there, it returns the text "Missing" instead of an error.
{"cells": {"A1": "Invoice", "B1": "System", "C1": "Bank", "D1": "Difference", "F1": "Invoice", "G1": "Bank", "A2": "INV-01", "B2": 250, "C2": "=XLOOKUP(A2,$F$2:$F$6,$G$2:$G$6,\"Missing\")", "D2": "=IF(C2=\"Missing\",\"Not in bank\",B2-C2)", "A3": "INV-02", "B3": 480, "C3": "=XLOOKUP(A3,$F$2:$F$6,$G$2:$G$6,\"Missing\")", "D3": "=IF(C3=\"Missing\",\"Not in bank\",B3-C3)", "A4": "INV-03", "B4": 120, "C4": "=XLOOKUP(A4,$F$2:$F$6,$G$2:$G$6,\"Missing\")", "D4": "=IF(C4=\"Missing\",\"Not in bank\",B4-C4)", "A5": "INV-04", "B5": 75.5, "C5": "=XLOOKUP(A5,$F$2:$F$6,$G$2:$G$6,\"Missing\")", "D5": "=IF(C5=\"Missing\",\"Not in bank\",B5-C5)", "A6": "INV-05", "B6": 310, "C6": "=XLOOKUP(A6,$F$2:$F$6,$G$2:$G$6,\"Missing\")", "D6": "=IF(C6=\"Missing\",\"Not in bank\",B6-C6)", "F2": "INV-03", "G2": 120, "F3": "INV-05", "G3": 301, "F4": "INV-01", "G4": 250, "F5": "INV-04", "G5": 75.5, "F6": "INV-06", "G6": 90}, "formats": {"B2:D6": {"fmt": "currency"}, "G2:G6": {"fmt": "currency"}}, "focus": "C2", "rows": 7, "note": "The bank list (F:G) is in a different order and has no INV-02."}
One formula finds both kinds of problems: INV-02 never reached the bank, and INV-05 was paid 9 short (310 against 301: swapped digits again).
In Excel 2019 and older, which don't have XLOOKUP, use the VLOOKUP equivalent:
=IFERROR(VLOOKUP(A2, $F$2:$G$6, 2, 0), "Missing")
To pull several columns at once, see VLOOKUP multiple columns with one formula.
5. Highlight the differences with colour
Formulas give you a column of answers. Conditional formatting paints the cells themselves:
- Select the first list, for example
A2:A8. - Home → Conditional Formatting → New Rule → Use a formula to determine which cells to format.
- Type
=COUNTIF($B$2:$B$8, A2)=0and choose a fill colour.
Every value of column A that is missing from column B is now highlighted, and it updates when the data changes.
Two quick alternatives with no formula at all:
- Duplicate Values. Select both columns → Conditional Formatting → Highlight Cells Rules → Duplicate Values. Choose Unique to colour the values that appear only once. It also flags repeats inside a single column, so use it for a quick look, not for a report.
- Row differences. Select both columns and press Ctrl + \. Excel selects every cell in the second column that differs from the first in the same row. Add a fill colour and you're done.
Excel 365: the whole answer in one formula
With dynamic arrays, FILTER returns the list of differences itself:
=FILTER(A2:A8, COUNTIF(B2:B8, A2:A8)=0)
That spills every value of A that is missing from B. Change =0 to >0 for the values that are in both. No helper column, no copying down.
Which method should you use?
| You want to… | Use |
|---|---|
| Compare cells in the same row | =A2=B2 or IF |
| Respect upper and lower case | EXACT |
| Know if a value exists in another list | COUNTIF(...)>0 |
| Know where it is | MATCH |
| Bring a value from the other table | XLOOKUP / VLOOKUP |
| Count matches or differences in one cell | SUMPRODUCT + COUNTIF |
| See the differences in colour | Conditional formatting |
| Get the list of differences (Excel 365) | FILTER + COUNTIF |
Common mistakes
- Hidden spaces.
"Cherry "is not"Cherry". Clean both lists withTRIMbefore comparing, especially data copied from a system or a PDF. - Numbers stored as text. The number
1024and the text"1024"don't match. If one list is aligned left and the other right, that's the reason. Convert the text to numbers first. - No dollar signs on the list.
COUNTIF(B2:B8, A2)copied down becomesB3:B9,B4:B10… and the last rows are checked against a shrinking list. Lock it:$B$2:$B$8. - Testing for
=1instead of>0. If a name appears twice in the other list, COUNTIF returns 2. Always test>0. - Comparing only one way. "Everything in A is in B" doesn't mean the lists are equal: B can have extra rows. Check both directions.
- Forgetting the
0in MATCH or VLOOKUP. Without it Excel does an approximate match and happily returns a wrong row.
Practise it
Each exercise checks your formula instantly: