How-to recipes · Analysis

How to find duplicates between two lists in Excel

Find the values that appear in both lists, or only in one, with FILTER and COUNTIF in Microsoft 365 or a MATCH helper column in older Excel.

Intermediate FILTER COUNTIF ISNUMBER MATCH XMATCH IF

You have two lists: the people who attended a January workshop and those who attended in February, last month's customer list and this month's, the products in the warehouse system and the products on the website. The questions are always the same: which items are on both lists? and which are missing from the other one? Eyeballing two columns does not scale beyond a dozen rows. This recipe shows formulas that answer both questions, plus a colour-coding trick.

The example data

January attendees are in A2:A7 and February attendees in C2:C7. The lists are in different orders, which is normal, and the formulas below do not care about order.

Microsoft 365: FILTER the values found in the other list

COUNTIF can take a whole range as its criteria. COUNTIF(C2:C7,A2:A7) returns, for each January name, how many times it appears in the February list. FILTER then keeps the names with a count above zero:

E2fx=FILTER(A2:A7,COUNTIF(C2:C7,A2:A7)>0,"None")
ABCDE
1JanuaryFebruary
2AnaChloeAna
3BenGusChloe
4ChloeAnaFemi
5DevHana
6EvaFemi
7FemiIvan

Ana, Chloe and Femi came to both workshops. The list keeps the January order.

Swap the condition to =0 to see who came in January but not February:

E2fx=FILTER(A2:A7,COUNTIF(C2:C7,A2:A7)=0,"None")
ABCDE
1JanuaryFebruary
2AnaChloeBen
3BenGusDev
4ChloeAnaEva
5DevHana
6EvaFemi
7FemiIvan

Ben, Dev and Eva did not return in February.

To get the February newcomers, reverse the ranges: =FILTER(C2:C7,COUNTIF(A2:A7,C2:C7)=0) returns Gus, Hana and Ivan. The third argument, "None", is shown when nothing matches; without it you would see #CALC!.

Excel 2016 and 2019: a helper column

Without FILTER, mark each row and then sort or filter. In B2, check whether the January name exists in the February list and copy down:

B2fx=IF(ISNUMBER(MATCH(A2,$C$2:$C$7,0)),"Yes","No")
ABC
1JanuaryIn Feb?February
2AnaYesChloe
3BenGus
4ChloeAna
5DevHana
6EvaFemi
7FemiIvan

Ana is found in the February list, so B2 shows Yes.

Result: Yes

  • MATCH with 0 as the last argument looks for an exact match and returns its position, or #N/A if it is missing.
  • ISNUMBER turns a position into TRUE and #N/A into FALSE.
  • IF shows a friendly Yes or No. =COUNTIF($C$2:$C$7,A2)>0 gives the same TRUE/FALSE and is just as good.

Now use Data > Filter on column B to show only Yes (in both lists) or only No (January only). The $ signs keep the February range fixed while you copy the formula down; see Cell references: relative, absolute and mixed.

Colour the matches instead

Select A2:A7, choose Home > Conditional Formatting > New Rule > Use a formula, and enter =COUNTIF($C$2:$C$7,A2)>0. Pick a green fill. Repeat for C2:C7 with =COUNTIF($A$2:$A$7,C2)>0. Both lists now show the shared names in green, and the colours update when you edit either list. The built-in Duplicate Values rule can do this too if you select both columns while holding Ctrl, but it also colours duplicates within one list, which may not be what you want.

When the lists are on different sheets

Nothing changes except the reference: =FILTER(A2:A7,COUNTIF(Feb!A2:A50,A2:A7)>0). In Excel 2016 conditional formatting can refer to another sheet directly, but a named range (Named ranges: give cells meaningful names) such as FebList makes the rule easier to read: =COUNTIF(FebList,A2)>0.

Pitfalls

  • Matching is not case-sensitive and ignores nothing else: Ana with a trailing space does not match Ana. Clean both lists with TRIM first.
  • A number in one list and the same number stored as text in the other do not match with MATCH or XMATCH. Check with =ISTEXT(A2) and convert using Data > Text to Columns > Finish.
  • COUNTIF supports wildcards, so a value containing * or ? can match more than it should. Replace them with ~* and ~? or use MATCH, which is safer for such codes.
  • For two lists of tens of thousands of rows, MATCH/XMATCH is faster than COUNTIF because it stops at the first match.
Tip. If you need to compare two lists row by row (is A2 the same as B2?), that is a different task: see How to compare two columns in Excel. To compare whole tables with several columns, join the key columns first, for example A2&"|"&B2, and compare the joined keys.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 16 KB

More how-to recipes