Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to dynamically extract a list of unique values from a column range in Excel?

For a column range which the values are changing regularly, and you always need to get all the unique values from the range no matter how it changed. How to make a dynamical list of unique values? This article will show you how to deal with it.

Dynamically extract a list of unique values from a column range with formula

Dynamically extract a list of unique values from a column range with VBA code


Easily select and highlight all unique values from a column range in excel:

The Select Duplicate & Unique Cells utility of Kutools for Excel can help you easily select and highlight all unique values (include the first duplicates) or the unique values except the first one, as well as duplicate values as you need as below screenshot shown.Download the full feature 60-day free trail of Kutools for Excel now!

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download the free trial Now!

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

Dynamically extract a list of unique values from a column range with formula

As below screenshot shown, you need to dynamically extract a list of unique values from range B2:B9. Please try the following array formula.

1. Select a blank cell such as D2, enter formula =IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$1:D1, $B$2:$B$9), 0)),"") (B2:B9 is the column data which you want to extract the unique values, D1 is the above cell where your formula is located) into the Formula Bar, and then press the Ctrl + Shift + Enter keys simultaneously. See screenshot:

2. Keep selecting cell D2, then drag the Fill Handle down to get all unique values from the specified range.

Now all unique values in column range B2:B9 are extracted. When values in this range changed, the unique value list will be dynamically changed immediately.


Dynamically extract a list of unique values from a column range with VBA code

You can also extract a list of unique values dynamically from a column range with the following VBA code.

1. Press Alt + F11 keys simultaneously to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click Insert > Module. Then copy and paste the below VBA code into the Module window.

VBA code: Extract a list of unique values from a range

Sub CreateUniqueList()
Dim xRng As Range
Dim xLastRow As Long
Dim xLastRow2 As Long
Dim I As Integer
On Error Resume Next
Set xRng = Application.InputBox("Please select range:", "Kutools for Excel", Selection.Address, , , , , 8)
If xRng Is Nothing Then Exit Sub
On Error Resume Next
xRng.Copy Range("D2")
xLastRow = xRng.Rows.Count + 1
ActiveSheet.Range("D2:D" & xLastRow).RemoveDuplicates Columns:=1, Header:=xlNo
xLastRow2 = Cells(Rows.Count, "B").End(xlUp).Row
For I = 1 To xLastRow2
  If ActiveSheet.Range("D2:D" & xLastRow2).Cells(I).Value = "" Then
     ActiveSheet.Range("D2:D" & xLastRow2).Cells(I).Delete
  End If
Next
End Sub

Note: In the code, D2 is the cell you will locate the unique value list. You can change it as you need.

3. Go back to the worksheet, click Insert > Shapes > Rectangle. See screenshot:

4. Draw a rectangle in your worksheet, then enter some words you need to display on it. Then right click it and select Assign Macro from the right-clicking menu. In the Assign Macro dialog box, select the CreateUniqueList in the Macro name box, and then click the OK button. See screenshot:

5. Now click on the rectangle button, a Kutools for Excel dialog box pops up, please select the range contains unique values you need to extract, and then click the OK button.

From now on, you can repeat the above step 5 to update the unique value list automatically.


Office Tab - Tabbed Browsing, Editing, and Managing of Workbooks in Excel:

Office Tab brings the tabbed interface as seen in web browsers such as Google Chrome, Internet Explorer new versions and Firefox to Microsoft Excel. It will be a time-saving tool and irreplaceble in your work. See below demo:

Click for free trial of Office Tab!

Office Tab for Excel


Related articles:


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

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!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Charlotte · 3 months ago
    I try the VBA Code and the formula. The code VBA is working very well but I can't keep a file with macro. But th problem is that I can't make the formula working. Did anybody have an idea ? Thank you
    • To post as a guest, your comment is unpublished.
      crystal · 3 months ago
      Hi Charlotte,
      Thank you for your comment. You can keep the file with macro for future use by saving the workbook as an Excel Macro-Enabled Workbook.
      For the formula problem, would you please provide a screenshot of your data? Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Cameron · 4 months ago
    I'm using that =IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$1:D1, $B$2:$B$9), 0)),"") formula which is great for one column but my data is spread across a range of columns and rows. Can I edit the formula to include the whole area? My data lives from AC4 to AR60...
  • To post as a guest, your comment is unpublished.
    Alexis · 9 months ago
    Hi, thank you for your help.
    Now, how can I have my values also sorted alphabetically? (I do not want to use the filter on my master table)
    Should I use a COUNTIFS instead of COUNTIF?
    Please HELP
    • To post as a guest, your comment is unpublished.
      crystal · 7 months ago
      Hi Alexis,
      Sorry can't hep to sort the extracted value alphabetically at the same time with formula. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Charley · 11 months ago
    I am trying to drag the formula down past my actual data so that I can input different sized data sets and not have to adjust anything. However, the last row after my actual data ends always returns a "0". I am using the unique values for something else in an adjacent column, and the 0 causes the last value to repeated (When I delete the 0 the value is no longer repeated). Any idea how to fix this? Also I am using Office 365 Business
  • To post as a guest, your comment is unpublished.
    Steve Parker · 1 years ago
    If I do this for a thousand row excel sheet on the latest version of Excel on a Mac, it never returns. The first row works, but when I duplicate down, excel goes into a compute mode that has not returned values for over two hours now.

    Any thoughts on how to do this for large lists (up to 2k rows) that will return 50 or 60 unique values?

    I mocked this up in the "Numbers" app, and it's working perfectly there, taking only a couple minutes to calculate. It's just taking so long in Excel that I wonder if it will ever complete. I plan on letting it "run" overnight to see what will happen.
    • To post as a guest, your comment is unpublished.
      Josh · 9 months ago
      Check your Calculating options. It needs to be set to automatic. File > Options > Formulas > Calculating options > Workbook Calculation (Automatic selection)
  • To post as a guest, your comment is unpublished.
    Matt · 1 years ago
    How would you add a second variable? For instance, I want all the unique elements in one column that also share a similar value in another column. In your example, imagine a 3rd column titled "Department" that would have values like product, meat, etc. I realize those are all Produce, but hopefully you get my point. Would you modify the CountIF formula to a COUNTIFS or do you modify it in another way?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Matt
      Please try this formula =IF(ISNA(VLOOKUP(A2,$C$2:$C$13,1,FALSE)),"Yes","").
      Supposing the two compared lists are Column A and Column C, If the unique values stay only in Column A but not in Column C, it will be displayed Yes in column B; while if return nothing in Column B, it means corresponding value stays in both Column A and Column C.
      • To post as a guest, your comment is unpublished.
        jyotiba mali · 1 years ago
        Thanks for the reply.. but hot to pull out that unique value if it displayed YES.. could you please advice me the formula to pull the unique value in different column.
  • To post as a guest, your comment is unpublished.
    Zac · 1 years ago
    How would you add multiple criteria, such as if you only wanted to add to the dynamic list if the date was just 9/12?

    I'm trying "&" in the MATCH formula, but it's not working.

    For example, based on your example:
    =IFERROR(INDEX($B$2:$B$9, MATCH(0 & B4,COUNTIF($D$1:D1, $B$2:$B$9) & $A$2:$A$9, 0)),"")
    This throws an error or creates duplicates.

    Alternatively, I've read that "+" might work, although I can't get it working. Or using SMALL.

    Ideas?
  • To post as a guest, your comment is unpublished.
    Mike · 1 years ago
    Hi Crystal,
    I am trying to use the VB version of the unique values list and running into an issue.
    The range that I want to create a unique values column from is all formulas that refer to different tabs.
    How does one get the value to transfer over instead of the formula?
    • To post as a guest, your comment is unpublished.
      Odette Meintjes · 1 years ago
      I have the same problem, except that my formula refer to column names and cannot convert to absolute.
      How do I change the vba to paste the values and not the formula?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Mike,
      Please convert your formula references to absolute, and then apply the VB script.
  • To post as a guest, your comment is unpublished.
    Jones · 2 years ago
    Any tips on getting the VBA option to work with Excel 2016 for macOS? I have followed the steps; however, when I run the macro, nothing happens at all. Thanks!
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Daer Jones,
      Please try the below VBA code and let me know whether it works for you. Thank you!

      Sub CreateUniqueList()
      Dim xRng As Range
      Dim xLastRow As Long
      Dim xLastRow2 As Long
      Dim I As Integer
      ' On Error Resume Next
      Set xRng = Application.InputBox("Please select range:", "Kutools for Excel", Selection.Address, , , , , 8)
      If xRng Is Nothing Then Exit Sub
      On Error Resume Next
      xRng.Copy Range("D2")
      xLastRow = xRng.Rows.Count + 1
      ActiveSheet.Range("D2:D" & xLastRow).RemoveDuplicates Columns:=1, Header:=xlNo
      xLastRow2 = Cells(Rows.Count, "B").End(xlUp).Row
      For I = 1 To xLastRow2
      If ActiveSheet.Range("D2:D" & xLastRow2).Cells(I).Value = "" Then
      ActiveSheet.Range("D2:D" & xLastRow2).Cells(I).Delete
      End If
      Next
      End Sub
  • To post as a guest, your comment is unpublished.
    Ryan · 2 years ago
    Also, for whatever reason, the original formula provided:
    =IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$1:D1, $B$2:$B$9), 0)),"")

    returns a "circular reference" warning and will not calculate..
    • To post as a guest, your comment is unpublished.
      Andrew · 1 years ago
      I've had this happen before - my fix was that I was entering the formula into the cell D1 (equivalent in the worksheet I was using). Whichever cell the $D:$1 corresponds to you need to be entering it in the cell below - D2. Apologies if that's not why you got the error
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Ryan,
      Which Office version do you use? The formula works well in my Office 2016 and 2013.
  • To post as a guest, your comment is unpublished.
    Ryan · 2 years ago
    Hello, and thank you for your help.

    I need exactly this functionality, but my list of "unique values" needs to extend across columns instead of rows, so the expanding list down the rows won't work for me.

    How can I modify this formula in order to make the "unique values" list expand as I drag it across the columns?

    Offset()?
    Transpose()?
    Indirect() with a string of absolute references concatenated with a reference to the column instead of row?


    Thanks again!
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Ryan,
      This formula =IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$2:D2, $B$2:$B$9), 0)),"") + Ctrl + Shift + Enter can help you to solve the problem.
      See below screenshot:
  • To post as a guest, your comment is unpublished.
    Viswanath Urala · 2 years ago
    {=INDEX($Q$3:$Q$263,MATCH(0,COUNTIF(V$2:V2,$Q$3:$Q$263),0))} - found this to work from another site...

    Use the Ctrl+Shift+Enter to get the array function (curly braces). Drag copy-paste the formulas until the #NA is shown. My data set was in Column-Q, it was compared to see if it existed in the unique's list in Column-V, which continually stretches along this same column.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good Day.
      Please list all unique values of column Q with the abobv formula, and then use his formula =IF(D2=V1,"Match","No match") to compare if the uniques in cilumn Q compareing to column V in the same row.
  • To post as a guest, your comment is unpublished.
    Outdated · 2 years ago
    This formula is outdated and doesn't work. I literally just set this exact excel sheet up to see if I could get this formula to work and it doesnt.
  • To post as a guest, your comment is unpublished.
    PJ · 2 years ago
    I am decent at excel but I am really trying to wrap my head around how and why the above formula works (it works for what I am using it for but I must understand why). I get a little confused using arrays sometimes so any explanation in idiots terms would be extremely helpful

    Regards
  • To post as a guest, your comment is unpublished.
    Eric · 2 years ago
    Thank you for the tutorial. Using the formula method, how would you alter the formula if you wanted to add a category qualifer? Say in column C you distinguish whether the item is a fruit or a vegetable. How would you change the code to only sort the unique fruits and exclude the vegetables? I tried replacing COUNTIF with COUNTIFS, using the second countifs criteria of (LIST RANGE,"CATEGORY") but it returns blank. Would I need to expand my array and incorporate VLOOKUP?