Menu

How to Compare Two Columns in Excel for Matches

To compare two columns row by row, use =A2=B2 (or EXACT for case). To find values in one column that are missing from the other, use COUNTIF, MATCH or XLOOKUP, and highlight the differences with conditional formatting.

Every sheet on this page is live: change a number or a formula and it recalculates.

To compare two columns row by row, type =B2=C2 next to the first row and fill it down: TRUE means the two cells match, FALSE means they differ. To find the values of one column that appear anywhere in another column, in any order, use =COUNTIF($B$2:$B$8,A2)>0 instead.

Old and new prices
D2
ABCDE
1ProductOldNewSame?Status
2Apple$1.20$1.20TRUESame
3Pear$1.50$1.60FALSEChanged
4Carrot$0.80$0.80TRUESame
5Bread$2.40$2.20FALSEChanged
6Milk$1.10$1.10TRUESame
7Cheese$4.50$4.90FALSEChanged
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

D3, D5 and D7 are FALSE, and the conditional formatting rule =$B2<>$C2 colours those three rows. Column E shows the same test with words instead of TRUE and FALSE. Change C3 to 1.5 and row 3 turns to Same.

Compare two columns with IF

=B2=C2 returns TRUE or FALSE. Wrap it in IF to choose the words: =IF(B2=C2,"Same","Changed"), as in column E above. To leave matching rows blank and mark only the differences, use =IF(B2<>C2,"Changed",""). To show by how much a number changed, subtract instead of comparing: =C2-B2.

To count the differences without a helper column, compare the two ranges inside SUMPRODUCT: =SUMPRODUCT(--(B2:B7<>C2:C7)) returns 3 for the sheet above.

Without a formula: select B2:C7 with B2 as the active cell, go to Home > Find & Select > Go To Special, choose Row differences and press OK (on Windows, Ctrl+\ does the same). Excel selects C3, C5 and C7, the cells that differ from column B in their row; give them a fill colour to mark them.

Case-sensitive comparison with EXACT

The = comparison ignores upper and lower case: ab12 equals AB12. When case matters (product codes, passwords, IDs), use EXACT(A2,B2), which is TRUE only when the two texts are identical character for character.

Codes with different case
C2
ABCD
1CodeEnteredEqual?EXACT
2AB12AB12TRUETRUE
3CD34cd34TRUEFALSE
4EF56EF56TRUETRUE
5GH78Gh78TRUEFALSE
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Column C, the = comparison, says all four match. EXACT says rows 3 and 5 differ, because cd34 and Gh78 use lower case letters.

Find values in one column that are missing from the other

When the two lists are not in the same order, compare each value with the whole other column. COUNTIF($B$2:$B$8,A2) counts how many times A2 appears in B2:B8, so >0 means "found" and =0 means "missing". The $ signs keep the searched range fixed while the formula is filled down.

January and February customers
C2
ABCD
1JanuaryFebruaryIn February?With MATCH
2AnaDanTRUETRUE
3BenFayTRUETRUE
4CaraAnaFALSEFALSE
5DanGusTRUETRUE
6EveHalFALSEFALSE
7FayIvyTRUETRUE
8GusBenTRUETRUE
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Cara and Eve are FALSE: they bought in January and not in February. MATCH gives the same answer by another route: MATCH(A2,$B$2:$B$8,0) returns the position of A2 in column B, or #N/A when it is not there, and ISNUMBER turns that into TRUE or FALSE. To check the other direction (new customers in February), put the same formula next to column B with the ranges swapped: =COUNTIF($A$2:$A$8,B2)>0.

Compare two lists and return a matching value

Often the question is not only "is it there" but "does the value next to it match". Here, invoices are compared with a list of payments in another order: XLOOKUP finds each invoice in the payments, returns what was paid, and column D compares it with the invoice amount.

Invoices against payments
C2
ABCDEFG
1InvoiceAmountPaidMatch?Payment forPaid
2INV-101120120TRUEINV-103240
3INV-10285Not paidFALSEINV-101120
4INV-103240240TRUEINV-105140
5INV-1046060TRUEINV-10695
6INV-105150140FALSEINV-10460
7INV-1069595TRUE
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

INV-102 has no payment, so C3 says Not paid. INV-105 was paid 140 instead of 150, so D6 is FALSE as well. The last argument of XLOOKUP, "Not paid", replaces the #N/A a missing value would give. XLOOKUP needs Excel 2021 or Microsoft 365; in Excel 2019 use =IFERROR(VLOOKUP(A2,$F$2:$G$6,2,FALSE),"Not paid"). The XLOOKUP page has the other arguments.

List the values missing from the other column

Instead of a TRUE/FALSE column, FILTER can return the missing values as a list. COUNTIF(B2:B8,A2:A8) with a range as its second argument counts every value of A at once, and FILTER keeps the ones where the count is 0.

Who did not come back
D2
ABCD
1JanuaryFebruaryNot in February
2AnaDan
3BenFay
4CaraAna
5DanGus
6EveHal
7FayIvy
8GusBen
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In D2, list the January customers who are not in the February list.

The answer spills Cara and Eve. =FILTER(A2:A8,ISNA(MATCH(A2:A8,B2:B8,0))) works too. If every customer came back, FILTER returns #CALC!; add a third argument for that case: =FILTER(A2:A8,COUNTIF(B2:B8,A2:A8)=0,"None"). FILTER needs Excel 2021 or Microsoft 365. See FILTER for more conditions.

Highlight the differences between two columns

The formulas above work as conditional formatting rules too. Select the first list, go to Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format, and enter the formula for its first cell. Here A2:A8 gets =COUNTIF($B$2:$B$8,A2)=0 and B2:B8 gets =COUNTIF($A$2:$A$8,B2)=0: every name that is in only one of the lists is coloured.

Names in only one list
A1
AB
1JanuaryFebruary
2AnaDan
3BenFay
4CaraAna
5DanGus
6EveHal
7FayIvy
8GusBen
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Cara and Eve are coloured in January, Hal and Ivy in February. For two columns that should match row by row, the rule is =$A2<>$B2 on both columns, as in the first sheet on this page. To colour the names that are in both lists instead, use >0, as on the [highlight duplicates](/docs/excel/highlight-duplicates) page.

Why identical values show as different

The most common reason is a space you cannot see: Ana with a trailing space is not equal to Ana. Data pasted from another system or a web page often carries them. Compare the trimmed values instead.

A hidden space
C2
ABCD
1NameOther listEqual?Trimmed
2AnaAna FALSETRUE
3BenBenTRUETRUE
4Cara CaraFALSETRUE
5DanDanTRUETRUE
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Column C says rows 2 and 4 differ; column D, after TRIM removes the spaces at both ends, says all four match. The other usual reason is a number stored as text in one column and a real number in the other: 101 and '101 look the same, but Excel's = comparison returns FALSE, and MATCH, VLOOKUP and XLOOKUP do not find one in the other. COUNTIF is the exception: it reads text that looks like a number as that number, so it counts them as equal. A green triangle in the cell's corner marks the text version; convert it with =VALUE(A2) or =A2*1, or select the cells and choose Convert to Number from the warning icon.

Frequently Asked Questions

How do I compare two columns in Excel for matches?

Row by row: type =A2=B2 in C2 and fill it down; TRUE means the two cells match. To check whether each value of A appears anywhere in B, use =COUNTIF($B$2:$B$8,A2)>0.

How do I compare two columns and return a value from the second?

Look the value up: =XLOOKUP(A2,$F$2:$F$7,$G$2:$G$7,"Not found") returns the matching value from G, or Not found. In Excel 2019 and older use =IFERROR(VLOOKUP(A2,$F$2:$G$7,2,FALSE),"Not found").

Is comparing two cells in Excel case-sensitive?

No. =A2=B2 treats abc and ABC as equal. For a case-sensitive comparison use =EXACT(A2,B2), which is TRUE only when every character matches, case included.

How do I list the values that are in one column but not the other?

In Excel 365 and 2021, =FILTER(A2:A8,COUNTIF(B2:B8,A2:A8)=0) spills every value of A2:A8 that does not appear in B2:B8.

Why does Excel say two identical values are different?

One of them usually has an extra space or is a number stored as text. Compare =TRIM(A2)=TRIM(B2) to rule out spaces, and convert text numbers with =VALUE(A2) or =A2*1.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED