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.
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:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | January | February | |||
| 2 | Ana | Chloe | Ana | ||
| 3 | Ben | Gus | Chloe | ||
| 4 | Chloe | Ana | Femi | ||
| 5 | Dev | Hana | |||
| 6 | Eva | Femi | |||
| 7 | Femi | Ivan |
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:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | January | February | |||
| 2 | Ana | Chloe | Ben | ||
| 3 | Ben | Gus | Dev | ||
| 4 | Chloe | Ana | Eva | ||
| 5 | Dev | Hana | |||
| 6 | Eva | Femi | |||
| 7 | Femi | Ivan |
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:
| A | B | C | |
|---|---|---|---|
| 1 | January | In Feb? | February |
| 2 | Ana | Yes | Chloe |
| 3 | Ben | Gus | |
| 4 | Chloe | Ana | |
| 5 | Dev | Hana | |
| 6 | Eva | Femi | |
| 7 | Femi | Ivan |
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/Aif it is missing. - ISNUMBER turns a position into TRUE and
#N/Ainto FALSE. - IF shows a friendly Yes or No.
=COUNTIF($C$2:$C$7,A2)>0gives 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:
Anawith a trailing space does not matchAna. 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.
A2&"|"&B2, and compare the joined keys.