How to extract unique values from multiple columns in Excel?

If you often work with datasets spread across several columns in Excel, you may face situations where certain values are duplicated within the same column or between different columns. In many reporting or data analysis tasks, it becomes necessary to identify and extract all unique values—those that appear only once across the whole selection, regardless of where they are located. Doing this manually can be time-consuming and error-prone, especially when dealing with large datasets or complex tables. Fortunately, Excel offers a range of methods to efficiently extract these unique values.
This guide introduces several solutions you can use based on your Excel version and your preferences—such as formulas suitable for all versions, dynamic array formulas for recent versions, the use of Kutools AI Aide for straightforward results, Pivot Tables for visual consolidation, and VBA code for automated extraction in complex scenarios.
Extract unique values from multiple columns with formulas
There are times when you would like to achieve this extraction with built-in Excel functions. This section details how to do so using two approaches: an array formula suitable for all versions of Excel, and a dynamic array formula available in newer versions like Excel 365 and Excel 2021. These methods are ideal when you want a direct formula-based solution, require frequent updating as your data changes, or need to avoid external add-ins or code.
Extract unique values from multiple columns with Array formula for all Excel versions
For compatibility across all Excel versions, using an array formula lets you extract unique values from several columns—even if your Excel does not support dynamic arrays. This approach utilizes a combination of INDIRECT, TEXT, MIN, IF, COUNTIF, ROW, and COLUMN functions, making it flexible for various data structures.
Suppose your data is located in the range A2:C9. To extract the unique values starting in cell E2, use the following procedure:
1. Click cell E2 (or the first cell of your output range), and input the following array formula:
=INDIRECT(TEXT(MIN(IF(($A$2:$C$9<>"")*(COUNTIF($E$1:E1,$A$2:$C$9)=0),ROW($2:$9)*100+COLUMN($A:$C),7^8)),"R0C00"),)&""
- A2:C9 is the data range from which you want to extract unique values.
- E1:E1 refers to the cells immediately above your first output cell and is necessary for tracking which entries have already been output.
- $2:$9 are the row references of your data; $A:$C are the column references. Adjust these as needed to fit your own worksheet layout.
2. Once you have entered the formula, instead of just pressing Enter, press Ctrl + Shift + Enter together to confirm it as an array formula. When done correctly, curly brackets {} will appear around your formula in the formula bar. Then, drag the fill handle from E2 down the column. Continue dragging until blank cells appear, indicating there are no more unique values left to extract. This process ensures all unique values will be displayed in the target column.
- $A$2:$C$9: Specifies the entire set of cells to examine for unique values.
- IF(($A$2:$C$9<>"")*(COUNTIF($E$1:E1,$A$2:$C$9)=0), ROW($2:$9)*100+COLUMN($A:$C),7^8):
- $A$2:$C$9<>"" ensures that blank cells are ignored.
- COUNTIF($E$1:E1,$A$2:$C$9)=0 makes sure that only new (not yet extracted) values are included.
- If both conditions are true, the corresponding output is a calculation based on the cell's row and column to generate a unique index number.
- If either condition is false, the formula returns a very large number (7^8) to prevent accidental selection.
- MIN(...): Identifies the lowest index number, effectively locating the position of the next available unique value within the data.
- TEXT(...,"R0C00"): Changes the index into a valid cell reference using the R1C1 style.
- INDIRECT(...): Converts the cell reference created above to a value from your data range.
- &"": Forces the formula result to be treated as text, ensuring no formatting surprises.
Extract unique values from multiple columns with formula for Excel 365, Excel 2021, and newer versions
If you use Excel 365, Excel 2021, or a newer version, you have access to dynamic array functions, which provide a simpler and more intuitive way to extract unique values from multiple columns. The UNIQUE and TOCOL functions make it easier and faster to combine data across columns and eliminate duplicates in a single step—especially useful for those working with constantly updating or larger datasets.
To use this method, simply select a blank cell (for example, E2, or wherever you'd like the results to appear), enter this formula, and press Enter:
=UNIQUE(TOCOL(A2:C9,1))
After pressing Enter, all unique values from the range A2:C9 will spill into the cells below the formula automatically. This feature is particularly efficient—the output updates dynamically as your source data changes, saving you manual refresh steps.
- TOCOL(A2:C9,1): Converts your range of values from multiple columns into a single column, removing blank cells automatically.
- UNIQUE(...): Extracts each value only once, providing a clean, de-duplicated list.
Extract unique values from multiple columns with Kutools AI Aide
If you’d like a more streamlined approach and want to reduce manual effort, Kutools AI Aide in Kutools for Excel can help you extract unique values from multiple columns with ease. This method is especially valuable if you aren’t familiar with formulas or want to avoid the risk of formula errors. Kutools AI Aide interprets your instructions and processes the data automatically, which is ideal for both beginners and users looking for a quick solution in just a few clicks.
After installation, click Kutools AI > AI Aide to open the "Kutools AI Aide" pane:
- Enter your request in the chat box, such as: "Extract unique values from the range A2:C9, ignoring blank cells, and place the results starting at E2:"
- Click "Send" or press Enter, then after AI analyzes the request, simply click "Execute" to run. The results will instantly appear in your worksheet, at the exact location you indicated.
Tip: This solution is very useful if your data extraction workflow varies or if you want natural language processing features. Remember to double-check the extracted list for blank cells if your original data is not perfectly consistent, as blank entries might be included or filtered based on your AI request details.
Extract unique values from multiple columns with Pivot Table
Pivot Tables are another convenient method for extracting unique values, particularly if you prefer working with visual tools and want to summarize or further analyze the unique items, such as counting occurrences. This approach is straightforward and doesn't require formulas. However, it requires a few steps of setup and slight data rearrangement, especially if the columns involved have different headings.
Here is a suggested process for extracting unique values using a Pivot Table:
1. Insert a new blank column immediately to the left of your data. For example, insert a new column A if your data starts at column B. This adjustment helps ensure correct range consolidation.
2. Select any cell within your dataset, press Alt + D, then quickly press P to launch the "PivotTable and PivotChart Wizard." In the wizard's first step, select "Multiple consolidation ranges." This allows you to combine values from numerous columns into a single summarized field.
3. Click Next, then choose "Create a single page field for me." This step organizes all your data as a single group for easier unique value extraction.
4. In the next step, select the entire data range (include the new blank column), click the Add button to bring your selection into the "All ranges" list, and click Next.
5. In the wizard's final step, select where you would like to place the Pivot Table (new worksheet or existing sheet), then click Finish to generate the Pivot Table report.
6. In the new Pivot Table, uncheck all fields in the "Choose fields to add to report" section to clear the default view.
7. Finally, drag the "Value" field to the Rows area. The Pivot Table will display all unique values from your original multi-column range, organized neatly in a single column.
Limitations: Data needs preliminary arrangement, and if your source dataset updates, you must refresh the Pivot Table to see new unique values.
Extract unique values from multiple columns with VBA code
In cases where you need to automate extraction or handle large and irregular datasets, using VBA (Visual Basic for Applications) code can provide a quick and reusable solution. This is ideal for users with basic familiarity with the Excel VBA editor, or for recurring tasks where you want to minimize manual operations. VBA can also handle large data volumes more efficiently than array formulas.
1. Open the VBA editor by pressing Alt + F11. In the "Microsoft Visual Basic for Applications" window that appears, click Insert > Module to add a new module.
2. In the new module, paste the code below:
VBA: Extract unique values from multiple columns
Sub Uniquedata()
'Updateby Extendoffice
Dim rng As Range
Dim InputRng As Range, OutRng As Range
Set dt = CreateObject("Scripting.Dictionary")
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
For Each rng In InputRng
If rng.Value <> "" Then
dt(rng.Value) = ""
End If
Next
OutRng.Range("A1").Resize(dt.Count) = Application.WorksheetFunction.Transpose(dt.Keys)
End Sub
3. Press F5 to run the code. A dialog will prompt you to select the data range. Select all relevant columns (including any with blank cells).
4. After clicking OK, another prompt asks where to output the unique values. Specify a top cell where you want the results listed (e.g., E2).
5. Click OK, and the macro will run automatically. All unique values will appear, starting at your specified location.
- If you receive errors like #VALUE! or #SPILL! when using formulas, check your ranges and ensure the output area is clear.
- Always check for hidden rows or merged cells in your data range, as these may affect the correctness of your unique value extraction.
- Array and dynamic array formulas update automatically with changes, but Advanced Filter and Pivot Table solutions may require manual refresh or re-run.
- For recurring tasks, consider automating extraction using VBA for consistency and speed.
- Back up your data before applying any mass extraction or automation routines, especially in complex workbooks.
More relative articles:
- Count The Number Of Unique And Distinct Values From A List
- Suppose you have a long list of values with some duplicate items, and you want to count how many unique values (the values that appear only once) or total distinct values exist in a column, as shown in the left screenshot. This article explains efficient methods for counting unique and distinct entries in Excel.
- Extract Unique Values Based On Criteria In Excel
- Suppose you want to extract only the unique names from column B based on a specific condition in column A, producing results as shown in the screenshot. This tutorial demonstrates ways to apply criteria when extracting unique values.
- Only Allow Unique Values In Excel
- If you want to allow only unique entries in a worksheet column and prevent duplicate values, this article introduces practical techniques to enforce uniqueness rules in Excel.
- Sum Unique Values Based On Criteria In Excel
- For example, you may need to sum only the unique values in an "Order" column based on names in an adjacent column, as shown in the screenshot. This article discusses approaches to combining unique and conditional calculations.
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!