Compare Two Columns for Matches and Differences

To compare two columns, either check them row by row with an equals sign, or check whether each value in one list exists anywhere in the other with COUNTIF. Describe your two lists below and get the formula.

Free, no sign-up required · 5 free generations a day

Last updated

Describe your task, get the formula

Type what you need in plain English, or pick an example below. You get the formula, a step-by-step explanation, and a worked example.

Formulas for comparing columns

Syntax
=A2=B2
=IF(COUNTIF($B$2:$B$100,A2)>0,"Match","Missing")
=FILTER(A2:A100,COUNTIF(B2:B100,A2:A100)=0)

The first formula compares two cells on the same row and returns TRUE or FALSE. The second looks for each value from column A anywhere in column B. The third lists every value from column A that column B does not contain; it needs Excel 365 or Google Sheets.

Examples

Flag values missing from the other list

=IF(COUNTIF($B$2:$B$100,A2)>0,"Match","Missing")

COUNTIF counts how often the value from A2 occurs in column B. Zero means it is missing. Copy the formula down beside column A.

List everything that is only in the first column

=FILTER(A2:A100,COUNTIF(B2:B100,A2:A100)=0)

Returns the values from column A that have no occurrence in column B as one spilled list.

Case-sensitive comparison of two cells

=IF(EXACT(A2,B2),"Same","Different")

The equals sign treats apple and Apple as equal. EXACT compares character by character, including case.

Common mistakes and how to fix them

Identical-looking values are reported as different

One has a trailing space, or one is a number and the other is text. Compare cleaned values: =TRIM(A2)=TRIM(B2), or convert both with VALUE.

Results change when the formula is copied down

The comparison range moved. Lock it with dollar signs: $B$2:$B$100.

#CALC! from the FILTER formula

Nothing is missing, so FILTER has no rows to return. Add a fallback as the third argument: =FILTER(A2:A100,COUNTIF(B2:B100,A2:A100)=0,"None").

Frequently asked questions

How do I highlight the differences instead?

Use conditional formatting with a formula rule. Select column A and apply the rule =COUNTIF($B$2:$B$100,A2)=0 to colour the values missing from column B.

How do I pull a related value for the matches?

Use a lookup: =XLOOKUP(A2,$B$2:$B$100,$C$2:$C$100,"Missing") returns the value from column C for each match and Missing for the rest.

How do I list the values that are in both columns?

Flip the condition: =FILTER(A2:A100,COUNTIF(B2:B100,A2:A100)>0) returns only the values that also appear in column B.

Don't want to write it by hand?

Describe what you need in plain English and get a ready-to-use formula in seconds.

Try the formula generator