How to Remove One List from Another (Excel, Google Sheets and Online)
· 5 minutes read

It is one of the most common spreadsheet chores: you have a list of all customers and a list of people who unsubscribed, a product catalogue and a list of discontinued items, or this month's attendees and last month's. What you need is list A with everything from list B removed – or the items the two lists have in common.
In set terms these are four operations:
- A minus B – items only in list A (this is "remove one list from another").
- B minus A – items only in list B.
- Intersection – items in both lists.
- Union – every item from both lists, each once.
The fastest way: compare two lists online
- Open compare two lists.
- Paste the main list into List A – one item per line, e.g. a column copied from Excel.
- Paste the list to remove or compare into List B.
- Choose the result: Only in A, Only in B, In both or All. Each tab shows how many items it contains.
- Copy or download the result.
Three options take care of the usual mismatches: Ignore capital letters (so Tom@example.com matches tom@example.com), Trim spaces (on by default, ignores stray spaces copied from cells) and Ignore empty lines. Both lists are compared in your browser – nothing is uploaded, which matters when you are working with customer e-mail addresses.
How to remove one list from another in Excel
Put list A in column A and list B in column B, starting in row 2.
Any Excel version – helper column:
- In C2 enter
=COUNTIF($B$2:$B$1000, A2)=0and fill it down. - Turn on Data → Filter and filter column C for
TRUE. - The visible values in column A are A minus B. Copy them to a new sheet.
Excel 365 – one formula:
=FILTER(A2:A1000, COUNTIF(B2:B1000, A2:A1000)=0)
Swap the ranges to get B minus A. For the intersection, drop the =0:
=FILTER(A2:A1000, COUNTIF(B2:B1000, A2:A1000))
And for a de-duplicated union:
=UNIQUE(VSTACK(A2:A1000, B2:B1000))
Be aware that COUNTIF ignores letter case and treats * and ? in the values as wildcards – a list item like item* can match more than you expect. If your data contains those characters, use =ISNA(XMATCH(A2, $B$2:$B$1000)) in the helper column instead – XMATCH does an exact match without wildcards by default.
How to compare two lists in Google Sheets
A minus B:
=FILTER(A2:A, A2:A<>"", COUNTIF(B2:B, A2:A)=0)
Items in both lists:
=FILTER(A2:A, A2:A<>"", COUNTIF(B2:B, A2:A)>0)
Union without duplicates:
=UNIQUE(FILTER({A2:A; B2:B}, {A2:A; B2:B}<>""))
To highlight the differences instead of extracting them, select A2:A, open Format → Conditional formatting, choose Custom formula is and enter =COUNTIF($B$2:$B, A2)=0.
How to subtract lists on the command line
With comm (Linux and macOS), both inputs must be sorted:
comm -23 <(sort -u a.txt) <(sort -u b.txt) # only in A
comm -13 <(sort -u a.txt) <(sort -u b.txt) # only in B
comm -12 <(sort -u a.txt) <(sort -u b.txt) # in both
If you want to keep the original order of list A, use grep:
grep -vxFf b.txt a.txt
-F treats lines as plain text, -x requires the whole line to match, -f b.txt reads the patterns from list B and -v inverts the match. Add -i to ignore case. Do not drop -x: without it, an empty line in b.txt would match – and remove – every line of a.txt.
In PowerShell:
$b = Get-Content b.txt
Get-Content a.txt | Where-Object { $b -notcontains $_ }
-notcontains is case-insensitive; use -cnotcontains for a case-sensitive comparison.
Common pitfalls
- Trailing spaces.
anna@example.comandanna@example.com␣look identical but do not match. Trim both lists. - Letter case. E-mail addresses are effectively case-insensitive, product codes may not be. Choose deliberately.
- Windows line endings. A file saved on Windows ends lines with
\r\n. Command-line tools then seeitem\rand nothing matches. Convert withdos2unixortr -d '\r'. - Accents. "Jan" and "Ján" are different strings. Remove accents first with the diacritic remover if they should match.
- Duplicates within a list. Decide whether you want them in the output. The online tool lists every item once; the duplicate remover cleans up a single list.
FAQ
What is the difference between "A minus B" and "B minus A"?
A minus B is everything in the first list that is missing from the second. B minus A is the opposite. If you want all differences at once, take both results – together they are the symmetric difference.
Can I compare lists with thousands of items?
Yes. The online list comparison handles hundreds of thousands of lines in a fraction of a second, because it uses hash sets rather than comparing every pair.
How do I compare lists that are not one item per line?
Split them first. If items are separated by commas, convert them to lines with the separator converter, or remove unwanted lines with remove lines containing.
Is my data stored?
No. The comparison runs locally in your browser. The lists are only remembered in your own browser's storage so they survive a page reload; clearing the inputs removes them.