DataTools AI DataTools AI

How to compare two lists in Google Sheets (find matches and missing items)

Comparing two lists is one of the most common spreadsheet chores: which customers from last month's export are missing from this month's, which emails on the event list never signed up for the newsletter, which SKUs are in the supplier file but not in your catalog. The examples below assume list A is in column A and list B is in column B, both with a header in row 1 and data from row 2 down.

En español: cómo comparar dos listas en Google Sheets.

Before you start: normalize both lists

Most "missing" items aren't really missing. They differ by a trailing space, a non-breaking space copied from a web page (CHAR(160)), or a number stored as text in one list and as a number in the other. Clean both lists the same way in helper columns before comparing. For list A, in a free column:
=ARRAYFORMULA(IF(A2:A="", "", LOWER(TRIM(SUBSTITUTE(A2:A, CHAR(160), " ")))))
Do the same for list B, then point the formulas below at the two helper columns instead of A and B. SUBSTITUTE turns the non-breaking spaces into normal ones, TRIM removes spaces at the ends and doubles in the middle, and LOWER makes the case consistent. Because SUBSTITUTE always returns text, a number like 1045 and the text "1045" end up identical.

COUNTIF, MATCH and XLOOKUP already ignore upper and lower case, so LOWER isn't strictly needed for them, but it keeps the cleaned lists consistent for UNIQUE (which is case-sensitive) and for reading. The guide to removing extra spaces covers tabs, line breaks and other invisible characters.

Step 1: is each item of A in B? (COUNTIF)

In C2, next to the first item of list A:
=IF(A2="", "", IF(COUNTIF(B$2:B, A2)>0, "In both", "Only in A"))
Fill it down. COUNTIF counts how many times the value appears in list B; anything above 0 is a match. The A2="" check keeps the empty rows below your list from getting a label too. To fill the whole column with one formula:
=ARRAYFORMULA(IF(A2:A="", "", IF(COUNTIF(B2:B, A2:A)>0, "In both", "Only in A")))

One catch: COUNTIF treats * and ? as wildcards and reads values that start with >, < or = as comparisons. For product codes or anything that may contain those characters, use XLOOKUP (Step 3).

Step 2: the same with MATCH and ISNA

MATCH returns the position of the value in list B, or #N/A when it isn't there. ISNA turns that into TRUE/FALSE:
=ISNA(MATCH(A2, B$2:B, 0)) returns TRUE when A2 is missing from B.
=ISNUMBER(MATCH(A2, B$2:B, 0)) returns TRUE when A2 is in B.
The last argument, 0, asks for an exact match; leave it out and MATCH assumes the list is sorted and can return wrong positions.

Step 3: bring back related data with XLOOKUP

When list B is a table (say, emails in B and plan names in C), XLOOKUP can tell you whether the item exists and return a value from the same row:
=XLOOKUP(A2, B$2:B, C$2:C, "Not found")
The fourth argument is what to show when there is no match. XLOOKUP's default mode is an exact match that doesn't use wildcards, so it is the safest choice for codes with * or ?. If list B is on another tab, use a reference such as 'List B'!A2:A.

Step 4: list what is missing with FILTER

To get a separate list instead of a column of labels, put these on an empty tab or column.

If a list has repeated values, wrap the formula in UNIQUE, for example =UNIQUE(FILTER(A2:A, A2:A<>"", COUNTIF(B2:B, A2:A)=0)). When nothing matches, FILTER returns an error ("No matches are found in FILTER evaluation"); wrap it in IFERROR to show a friendlier message: =IFERROR(FILTER(A2:A, A2:A<>"", COUNTIF(B2:B, A2:A)=0), "Nothing missing"). If you prefer MATCH, =FILTER(A2:A, A2:A<>"", ISNA(MATCH(A2:A, B2:B, 0))) gives the same list as the first formula.

Step 5: highlight missing items with conditional formatting

  1. Select A2:A (or A2:A1000).
  2. Open Format → Conditional formatting, and under Format rules choose Custom formula is.
  3. Enter =AND(A2<>"", COUNTIF($B$2:$B, A2)=0), pick a fill color and click Done.

The formula is written for the first cell of the range (A2) and Sheets adjusts it for the rest; the dollar signs keep list B fixed. For the other direction, select B2:B and use =AND(B2<>"", COUNTIF($A$2:$A, B2)=0). To highlight matches instead of missing items, change =0 to >0.

Conditional formatting can't refer to another tab directly. If list B lives on a tab called "List B", use INDIRECT: =AND(A2<>"", COUNTIF(INDIRECT("'List B'!A2:A"), A2)=0). For highlighting repeats within a single list, see how to highlight duplicates.

Step 6: comparing emails and phone numbers

Emails: lowercase and trim both lists before comparing, so "[email protected] " matches "[email protected]":
=ARRAYFORMULA(IF(A2:A="", "", LOWER(TRIM(SUBSTITUTE(A2:A, CHAR(160), "")))))
Here the non-breaking space is removed rather than replaced, since an email address never contains spaces. The email cleaning guide covers the other usual problems.

Phone numbers: the same number can be written as "+1 (555) 010-2030", "555-010-2030" or 5550102030. Keep only the digits, then compare the last 10:
=ARRAYFORMULA(IF(A2:A="", "", RIGHT(REGEXREPLACE(A2:A&"", "\D", ""), 10)))
&"" turns numbers into text so REGEXREPLACE accepts them, and \D matches anything that isn't a digit. Comparing the last 10 digits ignores the country code, which works for numbers with a 10-digit national number, such as the US, Canada and Mexico; for other countries, adjust the 10 or format both lists the same way first (see how to format phone numbers).

Step 7: check the result

Doing this every week? CleanSheet does all of these steps in one click: removes duplicates (even "Juan Perez" vs "juan pérez"), formats phones to E.164, lowercases emails and standardizes dates. Free up to 500 rows. See CleanSheet · Get the $9 template