To get unique values from two lists in Excel, use the UNIQUE function combined with VSTACK (Microsoft 365 or Excel 2024): =UNIQUE(VSTACK(A2:A10, B2:B10)). This returns a single column of all distinct items from both ranges, removing duplicates. For older Excel versions, use a formula with INDEX, MATCH, and COUNTIF, or the Power Query editor.
What “Unique” Means in This Context
When people ask for “unique from two lists,” they usually want one of two things: a list of items that appear in either list with no repeats (distinct values), or a list of items that appear in only one of the two lists (true unique, i.e., not in the other). The word “unique” is ambiguous in everyday language. In Excel, the UNIQUE function returns all distinct values from a single range—it removes duplicates. If you need items that exist in only one list, you need a different approach, such as comparing the two lists with COUNTIF or using set operations.
The Modern Way: UNIQUE and VSTACK
If you have Excel 365 or Excel 2024, the simplest solution uses VSTACK to stack the two columns vertically, then UNIQUE to extract distinct values.
Assume List 1 is in A2:A10 and List 2 is in B2:B10. In cell D2, enter:
=UNIQUE(VSTACK(A2:A10, B2:B10))
This spills the result down automatically. If your lists have different lengths, VSTACK handles that fine—it stacks them exactly as they are. For example, if A2:A5 has {Apple, Banana, Cherry, Apple} and B2:B4 has {Banana, Date, Fig}, the formula returns {Apple; Banana; Cherry; Date; Fig}.
To get only items that appear in both lists (intersection), use:
=UNIQUE(FILTER(A2:A10, COUNTIF(B2:B10, A2:A10)>0))
To get items that appear in only one list (symmetric difference), you can use:
=UNIQUE(VSTACK(FILTER(A2:A10, COUNTIF(B2:B10, A2:A10)=0), FILTER(B2:B10, COUNTIF(A2:A10, B2:B10)=0)))
These formulas require Excel 365 or Excel 2024. On Mac, they work the same; on Excel for the web, they also work if you have a Microsoft 365 subscription.
Older Excel Versions: No UNIQUE or VSTACK
If you’re using Excel 2019, 2016, or earlier, you don’t have UNIQUE or VSTACK. You can still get a distinct list with a classic array formula. Assume both lists are in column A (A2:A100) and column B (B2:B100), and you want a combined distinct list starting at D2.
First, combine the two lists into one column using an IF formula that stacks them. In C2, enter:
=IF(ROW()-ROW($C$2)+1 <= COUNTA($A$2:$A$100), INDEX($A$2:$A$100, ROW()-ROW($C$2)+1), INDEX($B$2:$B$100, ROW()-ROW($C$2)+1-COUNTA($A$2:$A$100)))
Drag down until you have enough rows to cover both lists. Then in D2, enter the following array formula (confirm with Ctrl+Shift+Enter on Windows, Cmd+Shift+Enter on Mac):
=IFERROR(INDEX($C$2:$C$200, MATCH(0, COUNTIF($D$1:D1, $C$2:$C$200), 0)), "")
This formula extracts distinct values from the combined list. It’s an array formula, so you must enter it with Ctrl+Shift+Enter, and it will fill down as you drag. The result is a list of unique items from both lists, but it’s clunkier and requires a helper column.
Using Power Query to Combine and Remove Duplicates
Power Query (Get & Transform) is available in Excel 2016 and later, and it’s a robust alternative that doesn’t require formulas. It works on Windows and Mac (though the interface differs slightly). Steps:
- Select the first list, go to Data > From Table/Range (or Data > Get Data > From Other Sources > From Table/Range). Create a table if prompted.
- In Power Query Editor, go to Home > Append Queries > Append Queries as New.
- Select the second table and click OK. This stacks the two lists.
- Select the column with the values, then go to Home > Remove Rows > Remove Duplicates.
- Click Close & Load to put the result back into a worksheet.
This method is ideal if you need to refresh the data when the source lists change—just refresh the query. It also works with lists in different sheets or workbooks.
How to Choose the Right Method
Your choice depends on your Excel version and your needs:
- Excel 365/2024: Use
UNIQUE+VSTACKfor simplicity and dynamic updates. - Excel 2019 or older: Use the array formula with helper column, or Power Query if you prefer a no-formula approach.
- Lists in different sheets: Reference them directly, e.g.,
=UNIQUE(VSTACK(Sheet1!A2:A10, Sheet2!B2:B10)). - Need to update often: Dynamic array formulas (365) or Power Query refresh automatically; the older array formula requires dragging and recalculating.
- Need to remove blanks: Wrap the range with
FILTERto exclude blanks, e.g.,=UNIQUE(FILTER(VSTACK(A2:A10,B2:B10), VSTACK(A2:A10,B2:B10)<>"")).
Common Problems and Fixes
Several issues trip up users when extracting unique values:
- #SPILL! error: The result doesn’t have enough empty cells below. Clear the cells below the formula or move it to a new column.
- #VALUE! error: Often because the ranges have different sizes or contain errors. Ensure both ranges are single columns (or rows) and have no error values.
- Case sensitivity:
UNIQUEis case-sensitive by default. “Apple” and “apple” are treated as different. If you want case-insensitive, useUNIQUEwith a helper column that normalizes case, e.g.,=UNIQUE(LOWER(VSTACK(A2:A10,B2:B10))). - Trailing spaces: Values with extra spaces are considered different. Use
TRIMto clean data first:=UNIQUE(TRIM(VSTACK(A2:A10,B2:B10))). - Blanks: Empty cells are treated as a value and appear in the result. Filter them out as shown above.
Comparing with Other Approaches
There are several other ways to get unique values from two lists, each with trade-offs:
- Conditional Formatting: Highlight duplicates in both lists, but this doesn’t produce a separate list of unique values. It’s useful for visual inspection.
- PivotTable: Combine the lists into one column, then create a PivotTable and drag the field to Rows. It shows distinct items but requires manual steps.
- Advanced Filter: Use Data > Advanced, choose “Copy to another location,” check “Unique records only.” This works only on a single column, so you’d need to combine lists first.
- VBA Macro: You can write a macro to loop through both ranges and collect unique values into a dictionary. This is overkill for most users, but it’s an option for automation. If you use VBA, remember to save a copy of your workbook before running the macro because macros cannot be undone with Ctrl+Z.
For most users, UNIQUE + VSTACK is the fastest and most maintainable method. For older versions, Power Query is the most reliable no-formula solution.
Frequently Asked Questions
Can I get unique values from two lists without VSTACK?
Yes. In Excel 365, you can use UNIQUE with a range that includes both columns if they are adjacent, e.g., =UNIQUE(A2:B10) returns unique rows, not a single list. To get a single column, you can use =UNIQUE(CHOOSE({1,2}, A2:A10, B2:B10)) but that returns an array, not a single column. The classic approach is to stack with IF as shown above, or use Power Query.
Why does my UNIQUE formula return #SPILL!?
The #SPILL! error means the formula wants to output more than one value, but something is blocking the cells below. Check that the cells directly below the formula are empty. Also, if the formula is inside an Excel table, it may not spill correctly—move it outside the table.
How do I get items that appear in only one of the two lists?
Use the symmetric difference formula shown earlier: =UNIQUE(VSTACK(FILTER(A2:A10, COUNTIF(B2:B10, A2:A10)=0), FILTER(B2:B10, COUNTIF(A2:A10, B2:B10)=0))). This returns items that are in A but not B, plus items in B but not A.
Does UNIQUE work with numbers and text mixed?
Yes, UNIQUE works with any data type, including numbers, text, dates, and even errors (though errors are treated as values). If you have numbers stored as text, they will be treated as text, so “123” and 123 are different.
Can I use this with lists on different sheets?
Absolutely. Just reference the other sheet in the formula, e.g., =UNIQUE(VSTACK(Sheet1!A2:A10, Sheet2!B2:B10)). The same applies to Power Query—you can append queries from different sheets or workbooks.
Is there a way to do this without formulas, just using menus?
Yes, Power Query is menu-driven and doesn’t require formulas. Also, you can use the Advanced Filter if you first combine the lists into one column manually (copy and paste). But for a dynamic solution, Power Query is the best menu-only method.
Related
- Generating Random Numbers in Python: A Complete Guide
- Python String z Order: Sorting and Comparison
- T-SQL Random Number: RAND, NEWID, and How to Use Them
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- DATEDIF in Excel: Is It Still Available?Yes—DATEDIF still works in Microsoft Excel for Microsoft 365, even though it is a legacy function that may…
- Spreadsheet VLOOKUP: How It Works & How to Use ItVLOOKUP in Excel searches for a value in the first column of a table and returns a corresponding…
- Excel OFFSET Function: How to Use It in Formulas and RangesIn Excel for Microsoft 365 on Windows, OFFSET returns a reference moved a chosen number of rows and…
- Remove Spaces in Excel Rows: Trim, Find, and ReplaceTo clean spaces at the start or end of text, or reduce repeated spaces between words, use Excel’s…
- Excel Split Cells With Regex: Formulas and MethodsYes—Excel for Microsoft 365 can split text using a regular expression by replacing regex-matched separators with a marker…
- AVERAGEIF in Excel: How It Works and When to Use ItAVERAGEIF in Excel calculates the average of numbers that meet one condition. Give it a range to check,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.