Compare Two Lists in Excel for Differences

Find items missing from one Excel list or the other with COUNTIF, XMATCH and FILTER, and learn how cleanup, case and duplicates change the result.

To find the differences between two lists in Excel, test each item in one list for a match in the other. A helper column with COUNTIF or MATCH works in every current version of Excel. In Microsoft 365 or Excel 2021 and later, FILTER combined with XMATCH can return the missing items as a separate list. Run the check in both directions: items in List A but not in List B are a different result from items in List B but not in List A.

Before you choose a formula, decide what "difference" means for your data. Most people mean membership: which values appear in one list and nowhere in the other, regardless of order. Some people mean a row-by-row comparison, where row 2 of one column is checked against row 2 of the other. These questions need different formulas, and using the wrong one gives misleading results.

A hypothetical example used throughout

The formulas below use this hypothetical layout. List A is in A2:A5 and List B is in B2:B4.

Row | Column A (List A) | Column B (List B)
2 | Alice | Ben
3 | Ben | Dan
4 | Chloe | Erin
5 | Dan |

The correct result is that Alice and Chloe are only in List A, Erin is only in List B, and Ben and Dan appear in both. Each method below should reproduce that result. You can use that as a check before applying a method to your real data.

Prepare the lists before comparing

Exact-match formulas compare values exactly as stored, so formatting differences that are invisible on screen will show up as false differences. Clean both lists first, or compare cleaned helper columns:

  • Extra spaces: TRIM removes leading, trailing and repeated internal spaces. It does not remove non-breaking spaces, which are common in data copied from web pages. Replace them with SUBSTITUTE(A2,CHAR(160)," ") before trimming.
  • Nonprinting characters: CLEAN removes many control characters that come from imports.
  • Numbers stored as text: an ID stored as text and the same ID stored as a number may not match, depending on the function. Convert both lists to the same type before comparing.
  • Blank cells: leave blanks out of the ranges you compare, or exclude them in the formula, so they are not reported as differences.
  • Name and label variants: exact matching treats "Smith, John" and "John Smith" as different values. Formulas cannot reconcile these variants, so standardize the format first.

A combined cleanup formula for a helper column might look like this:

=TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," ")))

Flag differences in another column with COUNTIF

This method works in any version of Excel. It labels each row instead of extracting a new list. In C2, enter the formula below and fill it down to C5:

=IF(COUNTIF($B$2:$B$4,A2)=0,"Only in A","In both")

With the example data, C2:C5 returns Only in A, In both, Only in A, In both. To check the other direction, put the mirror formula next to List B and fill it down:

=IF(COUNTIF($A$2:$A$5,B2)=0,"Only in B","In both")

Two caveats apply. COUNTIF is not case-sensitive, so "ben" matches "Ben". COUNTIF also treats *, ? and ~ in the lookup value as wildcard characters, so an item that contains an asterisk or question mark can match entries it should not. If your data contains those characters, use XMATCH or MATCH instead.

Flag differences with MATCH or XMATCH

MATCH returns #N/A when it finds no match, so wrapping it in ISNA returns TRUE for missing items. This works in all current versions:

=ISNA(MATCH(A2,$B$2:$B$4,0))

In Microsoft 365 and Excel 2021 or later, XMATCH does the same job. XMATCH defaults to exact matching and treats wildcard characters as literal text unless you request wildcard mode, which makes it the safer choice for data that contains * or ?:

=ISNA(XMATCH(A2,$B$2:$B$4))

For the example data, both formulas return TRUE for Alice and Chloe and FALSE for Ben and Dan. MATCH with match type 0 still interprets wildcard characters in text lookups, so the wildcard caveat for COUNTIF applies to MATCH as well. None of these three functions distinguishes uppercase from lowercase.

Return the missing items as a separate list with FILTER

If you want the differences extracted rather than flagged, use FILTER, which is available in Microsoft 365 and Excel 2021 or later. Enter this formula in an empty cell with enough empty space below it for the results to spill:

=FILTER(A2:A5,ISNA(XMATCH(A2:A5,B2:B4)),"None")

With the example data, this returns Alice and Chloe. Swap the ranges to list what is in B but missing from A, which returns Erin:

=FILTER(B2:B4,ISNA(XMATCH(B2:B4,A2:A5)),"None")

If your ranges include blank cells, for example when you reference extra rows to allow for new entries, exclude the blanks explicitly. Wrap the result in UNIQUE if the source list contains repeated items and you want each difference listed once:

=UNIQUE(FILTER(A2:A100,(A2:A100<>"")*ISNA(XMATCH(A2:A100,B2:B100)),"None"))

Highlight differences with conditional formatting

To see differences in place without adding columns, select A2:A5 and go to Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format. Enter the rule below and choose a fill color:

=COUNTIF($B$2:$B$4,A2)=0

The formula must refer to the first cell of the selection (A2) with a relative reference. The other list must use absolute references. Repeat the process for List B with the ranges reversed. The built-in Duplicate Values rule is a quick alternative when you select both lists together, but it also highlights repeats within a single list. Use the formula rule when either list contains internal duplicates.

Compare row by row instead of by membership

If the two lists are aligned and you need to know whether each row matches its counterpart, compare the cells directly. =A2=B2 returns TRUE or FALSE and ignores case. =EXACT(A2,B2) is case-sensitive. With the example data, every row returns FALSE, even though Ben and Dan appear in both lists. This shows why a row-by-row check is the wrong tool when the order of the lists differs.

When case or duplicate counts matter

For a case-sensitive membership test, combine EXACT with SUMPRODUCT. This returns TRUE when no entry in List B matches A2 exactly, including case:

=SUMPRODUCT(--EXACT(A2,$B$2:$B$4))=0

Membership tests do not account for quantity. If an item appears twice in List A and once in List B, every method above reports it as present in both. When counts matter, as in reconciling inventory or transactions, compare how many times the value appears in each list:

=COUNTIF($A$2:$A$5,A2)-COUNTIF($B$2:$B$4,A2)

A positive result means the value occurs more often in List A, a negative result means it occurs more often in List B, and zero means the counts are equal. The wildcard caveat for COUNTIF applies here too.

Large or regularly refreshed lists

If you repeat the same comparison on new data, Power Query (Data > Get & Transform in Excel 2016 and later) can merge two tables with a Left Anti join, which keeps only rows from the first table that have no match in the second. A Right Anti join gives the reverse direction. This guide does not include performance measurements, so there is no evidence here on how formulas and Power Query compare in speed on large datasets.

Check the result before relying on it

  • Reconcile the counts: the number of non-blank items in List A should equal the items flagged "In both" plus the items flagged "Only in A". Use COUNTA and COUNTIF on the helper column to confirm.
  • Spot-check a few flagged items by searching for them in the other list with Ctrl+F. If a value appears to exist but is flagged as missing, look for stray spaces, non-breaking spaces or a number-versus-text mismatch.
  • Confirm both directions: an empty "Only in A" result does not mean the lists are identical, because List B may still contain extra items.
  • Recheck the ranges after adding rows. Fixed ranges such as $B$2:$B$4 will not include new entries. Converting the lists to Excel tables with Ctrl+T lets references expand automatically.