How to Dynamically Extract Unique Values from A Column List in Excel

Suppose we have a list of some objects in one column, and some of them are duplicate, they also can be replaced by typing different object name, here’s the question, how can we dynamically extract unique values from this list in time if they are changed frequently? This article will show you two methods to extract unique values from a dynamic list. If you are good at coding, you can edit VBA code to implement this requirement, if you are weak in coding, you can use some excel functions to extract unique values as well.

Dynamically Extract Unique Values from A Column List by Formula


Precondition:

Prepare a list of food. You can find that they are duplicate.

Dynamically Extract Unique Values1

Step 1: In any cell except A1:A15, enter the formula =IFERROR(INDEX($A$2:$A$15, MATCH(0,COUNTIF($C$1:C1, $A$2:$A$15), 0)),””).

Dynamically Extract Unique Values2

Step 2: As it is an array formula, so we need to press Ctrl+Shift+Enter simultaneously to get result.

Dynamically Extract Unique Values3

We get Seafood in this location.

Step 3: Drag the fill handle down to fill the other cells in C column. Till there is nothing to be shown in cell.

Dynamically Extract Unique Values4

So, the list in C column records all unique values from selected range.

Step 4: After above steps, we get all unique values from selected range. Now let’s try to update one value in selected range, and verify if C column can be updated accordingly.

x
How to Show All Named Ranges in Excel

For example, update the second ‘Seafood’ to ‘Orange Juice’.

Dynamically Extract Unique Values5

Verify that a new value is added in the end of Unique Value list directly. That means above formula works well and applies on C column properly.

Dynamically Extract Unique Values from A Column List by VBA Code


If you are familiar with coding, you can also through editing VBA code to implement extracting unique values dynamically.

Step 1: On current visible worksheet, right click on sheet name tab to load Sheet management menu. Select View Code, Microsoft Visual Basic for Applications window pops up.

Or you can enter Microsoft Visual Basic for Applications window via Developer->Visual Basic. You can also press Alt + F11 keys simultaneously to open it.

Step 2: In Microsoft Visual Basic for Applications window, click Insert->Module, enter below code in Module1:

Sub ExtractUniqueValue()

Dim xRng As Range

Dim xRow1 As Long

Dim xRow2 As Long

Dim i As Integer

On Error Resume Next

Set xRng = Application.InputBox("Please select range:", "Extract Unique Value", Selection.Address, , , , , 8)

If xRng Is Nothing Then Exit Sub

On Error Resume Next

xRng.Copy Range("C2")

xRow1 = xRng.Rows.Count + 1

ActiveSheet.Range("C2:C" & xRow1).RemoveDuplicates Columns:=1, Header:=xlNo

xRow2 = Cells(Rows.Count, "A").End(xlUp).Row

For i = 1 To xLastRow2

  If ActiveSheet.Range("C2:C" & xRow2).Cells(i).Value = "" Then

     ActiveSheet.Range("C2:C" & xRow2).Cells(i).Delete

  End If

Next

End Sub

Step 3: Save the codes, see screenshot below. And then quit Microsoft Visual Basic for Applications.

Dynamically Extract Unique Values6

Step 4: Click Developer->Macros to run Macro. Select ‘ExtractUniqueValue’ and click Run.

Dynamically Extract Unique Values7

Step 5: Extract Unique Value dialog pops up. Enter Select Range $A$2:$A$15. Click OK. In this step you can select the range you want to extract unique values.

Dynamically Extract Unique Values8

Step 6: Click OK and check the result. Verify that unique values are displayed in C column properly. The behavior is as same as the result in method 1 step# 3.

Step 7: If you update the original list, you have to run macro to refresh Unique Value list. This way can also dynamically extract unique values from original list.

Related Functions


  • Excel IFERROR function
    The Excel IFERROR function returns an alternate value you specify if a formula results in an error, or returns the result of the formula.The syntax of the IFERROR function is as below:= IFERROR (value, value_if_error)….
  • Excel INDEX function
    The Excel INDEX function returns a value from a table based on the index (row number and column number)The INDEX function is a build-in function in Microsoft Excel and it is categorized as a Lookup and Reference Function.The syntax of the INDEX function is as below:= INDEX (array, row_num,[column_num])…
  • Excel MATCH  function
    The Excel MATCH function search a value in an array and returns the position of that item.The MATCH function is a build-in function in Microsoft Excel and it is categorized as a Lookup and Reference Function.The syntax of the MATCH function is as below:= MATCH  (lookup_value, lookup_array, [match_type])….
  • Excel COUNTIF function
    The Excel COUNTIF function will count the number of cells in a range that meet a given criteria. This function can be used to count the different kinds of cells with number, date, text values, blank, non-blanks, or containing specific characters.etc.= COUNTIF (range, criteria)…

 

 

 

Related Posts

VBA Macro For VLOOKUP From Another Sheet
vba macro for vlookup from another sheet1

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Insert Comments in Protected Worksheet in Excel
insert commetns in protected workshee3

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel
convert text to upper cases1

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How To Hide Every Other Row in Excel (Using VBA)
hide every other row1

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how ...

How to Disable the Save As Prompt in Excel
disable save as prompt1

This post will show you how to use a VBA Macro to save an Excel file and overwrite any existing file without a prompt so that you are going to get the little window that says file already exists do ...

How to Count Cells that Contain even or odd numbers in Excel
count cells that contain even numbers5

This post will guide you how to count the number of cells that contain odd or even numbers within a range of cells using a formula in Excel 2013/2016.How do I count cells that contain odd numbers through the use ...

How to Count Cells that Contain negative Numbers in Excel

This post will guide you how to count the number of cells that contain negative numbers within a range of cells using a formula in Excel 2013/2016.You can count the number of negative numbers in your data using easy functions ...

How to Count Cells Are Not Blank or Empty in Excel
count non blank nonempty cells5

This post will guide you how to count cells that are not blank or empty in a given range cells using a formula in Excel 2013/2016.How do I count the number of cells that are not blank in a particular ...

How to Count Cells Less Than a Specific Value in Excel
count cells lessr than5

This post will guide you how to count the number of cells less than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are less than a specific ...

How to Count Cells Greater Than a Specific Value in Excel
count cells greater than 5

This post will guide you how to count the number of cells greater than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are greater than a specific ...

Sidebar