E-Mail 'Extract unique distinct values from a multi-column cell range' To A Friend
Email a copy of 'Extract unique distinct values from a multi-column cell range' to a friend
Email a copy of 'Extract unique distinct values from a multi-column cell range' to a friend
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
A slightly different approach to extract unique items from a N*M table (named as "tbl" in the formula).
So type say "Unique items from the table" in A1 and enter the following formula as an array into A2 and copy it down as far as necessary.(it is supposed column A to be free)
=INDEX(tbl,MIN(IF(COUNTIF($A$1:A1,tbl)=0,ROW(tbl)-MIN(ROW(tbl))
+1)),MATCH(0,COUNTIF($A$1:A1,INDEX(tbl,MIN(IF(COUNTIF($A$1:A1,tbl)=0,ROW(tbl)-MIN
(ROW(tbl))+1)),,1)),0),1)
Thank you! Your formula is working perfectly! No need for a "helper" column!
Awesome resource! Using Excel 2003 SP3 if I blank out any of the first 6 values (left to right / top to bottom) it turns all the cells to ZERO. Any suggestions?
Thanks! I have updated the formula and the attached excel file.
Hi,
How I can extend "tbl_text" as reported in your example??
I need to enlarge that range for a bigger table.
Thanks,
Fabio,
Use "Name Manager" to change range.
https://office.microsoft.com/en-us/excel-help/define-and-use-names-in-formulas-HA010147120.aspx
It works now!
Many thanks,
Fabio
Awesome. Unbelievable. This has got to be one of the coolest formulas ever. Well, certainly that I've had the need to dream requirements for. Thank you so much!
And you might also want to add to your bullet list at the top of the Answer section that it handles numbers and text together. Some of your other formulas weren't for both. I'd have to guess that you won't get many more requests for enhancing this because it does everything I can imagine and is just outright awesome. You've just made my day.
BTW, I'm not a big fan of named ranges for my application, so I hard code the range. The way I set it up is with headers in row A, the formula in A2 and drag it down. I have my original data range in B2:D4. Here's all of that hard coded. It's nothing more than a search and replace of yours, so there's no functionality change, just a formatting change to avoid named ranges and rearrangement of where things are.
=IFERROR(SMALL(IF(($B$2:$D$4"")*(ISNUMBER($B$2:$D$4))*(COUNTIF($A$1:A1, $B$2:$D$4)=0), $B$2:$D$4, ""), 1), IFERROR(INDEX($B$2:$D$4, SMALL(IF(SMALL(IF((COUNTIF($A$1:A1, $B$2:$D$4)=0)*(ISTEXT($B$2:$D$4)), COUNTIF($B$2:$D$4, "<"&$B$2:$D$4)+1, ""), 1)=IF((COUNTIF($A$1:A1, $B$2:$D$4)=0)*(ISTEXT($B$2:$D$4)), COUNTIF($B$2:$D$4, "<"&$B$2:$D$4)+1, ""), ROW($B$2:$D$4)-MIN(ROW($B$2:$D$4))+1), 1), MATCH(SMALL(IF((COUNTIF($A$1:A1, $B$2:$D$4)=0)*(ISTEXT($B$2:$D$4)), COUNTIF($B$2:$D$4, "<"&$B$2:$D$4)+1, ""), 1), INDEX(IF((COUNTIF($A$1:A1, $B$2:$D$4)=0)*(ISTEXT($B$2:$D$4)), COUNTIF($B$2:$D$4, "<"&$B$2:$D$4)+1, ""), SMALL(IF(SMALL(IF((COUNTIF($A$1:A1, $B$2:$D$4)=0)*(ISTEXT($B$2:$D$4)), COUNTIF($B$2:$D$4, "<"&$B$2:$D$4)+1, ""), 1)=IF((COUNTIF($A$1:A1, $B$2:$D$4)=0)*(ISTEXT($B$2:$D$4)), COUNTIF($B$2:$D$4, "<"&$B$2:$D$4)+1, ""), ROW($B$2:$D$4)-MIN(ROW($B$2:$D$4))+1), 1), , 1), 0), 1), ""))
EEK,
You are welcome!
If a blank cell is located anywhere in the tbl, the formula returns the blank. I guess technically a blank is a unique value in the tbl but I'm trying to make sure only relevant numbers are returned. Any thoughts on how to correct this?
Curious,
Get the example file:
Unique-distinct-values-from-multiple-columns-using-array-formulas-without-blanks.xls
Hi Oscar,
at the end there is a #N/A in this file can you please suggest me how to get rid of it.
thanks for your help.
Sandeep,
=IFERROR(formula, "")
This is great. Do you have an example where the values are just on one column? Thanks!
JP,
I can´t find an example but I created a workbook. Check it out:
Unique-distinct-list-from-a-column-sorted-A-to-Z-blanks.xls
I have tried the formulas in this article and some from other articles and comments, but none have worked for my particular problem. I'd appreciate any help/insight.
I have several worksheets, each with a table inserted. I would like to create the list of uniques in the column of the summary worksheet's table. The methods on this site work for creating a list from a 1/2/3 columns, but fails for multiple columns (in my case). I have 4 and I'd rather understand the "general" approach than keep creating ever more convoluted formulas as columns increase.
I have created a named range that spans 4 worksheets (in the Name Manager - Name: MultiPC Refers To=A[PC],B[PC],C[PC],D[PC] -- references 4 table columns on separate worksheets).
The formulas create several errors. Stepping through them, when it tries to evaluate INDEX(*MultiPC*,... it says that it will result in an error. The value for MultiPC shown below the formula is the absolute references for MultiPC (comma separated between sheets, e.g. Sheet1!$B$2:$B$31,Sheet2!$B$2:$B:23...).
I'm guessing it's because the named range doesn't consitute an array (not rectangular? is this the case with all non-contiguous ranges?). I'm not really sure if that's the problem and how to tackle it. I've thought about making hidden columns in a single worksheet for the unique list of each worksheet, then applying this approach. Another alternative might be to extend the 3-column method from here https://www.get-digital-help.com/extract-a-unique-distinct-list-from-three-columns-in-excel/ (add another nested IFERROR(INDEX...MATCH(...COUNTIF(... ), but again, I'm trying to learn a general solution that doesn't require an ever-expanding formula.
Of course, it'd be a cinch if I was allowed to use VBA for this project, but our workplace doesn't allow macros, so I'm stuck using formulas at the moment. What's your opinion? Thanks a lot!
So, I almost have it set. Using either of your array formulas below for refering to a 4-column list, I'm having trouble with a "0" (zero) being placed when blank cells are in the referenced columns. Any ideas of how to eliminate this zero? If I reference 3 columns only, there's no problem. by the way, thanks so much for the info on your website.
=IFERROR(IFERROR(IFERROR(IFERROR(INDEX(List1, MATCH(0, COUNTIF($E$1:E1, List1), 0)), INDEX(List2, MATCH(0, COUNTIF($E$1:E1, List2), 0))), INDEX(List3, MATCH(0, COUNTIF($E$1:E1, List3), 0))), INDEX(List4, MATCH(0, COUNTIF($E$1:E1, List4), 0))), "")
=IFERROR(INDEX($B$15:$D$64, MIN(IF((COUNTIF($F$14:$F14, $B$15:$D$64)=0)*($B$15:$D$64""), ROW($B$15:$D$64)-MIN(ROW($B$15:$D$64))+1)), MATCH(0, COUNTIF($F$14:$F14, INDEX($B$15:$D$64, MIN(IF((COUNTIF($F$14:$F14, $B$15:$D$64)=0)*($B$15:$D$64""), ROW($B$15:$D$64)-MIN(ROW($B$15:$D$64))+1)), , 1)), 0), 1),"")
Colin,
See this workbook:
https://www.get-digital-help.com/wp-content/uploads/2014/10/Unique-distinct-values-from-four-ranges-with-blanks.xlsx
Named ranges
List1:=Sheet1!$A$1:$A$7
List2:=Sheet1!$C$1:$C$7
List3:=Sheet1!$E$1:$E$7
List4:=Sheet1!$G$1:$G$8
Zeta,
I have several worksheets, each with a table inserted. I would like to create the list of uniques in the column of the summary worksheet's table. The methods on this site work for creating a list from a 1/2/3 columns, but fails for multiple columns (in my case). I have 4 and I'd rather understand the "general" approach than keep creating ever more convoluted formulas as columns increase.
Here is an example of four columns:
how-to-extract-a-unique-list-from-four-columns-in-excel.xlsx
I'm guessing it's because the named range doesn't consitute an array (not rectangular? is this the case with all non-contiguous ranges?). I'm not really sure if that's the problem and how to tackle it. I've thought about making hidden columns in a single worksheet for the unique list of each worksheet, then applying this approach. Another alternative might be to extend the 3-column method from here https://www.get-digital-help.com/extract-a-unique-distinct-list-from-three-columns-in-excel/ (add another nested IFERROR(INDEX...MATCH(...COUNTIF(... ), but again, I'm trying to learn a general solution that doesn't require an ever-expanding formula.
I am sorry, I don´t have a general solution to this problem.
Oscar,
I really appreciate your reply. Your site is an incredible resource. I used the 4-column formula you provided, but if I find a method that works for N columns across multiple sheets, I will let the folks here know!
Thanks again,
Z
Hi guys,
i have question, what i must do if i want to have duplicates data.
i mean in sort list i want to see duplicates.
Can you help me plzzz
Goran,
read this post:
Sort a range from A to Z using array formula
Oscar,
Ty vm its helps :)
Oscar,
i read post but i have problem....what i must do or change in this formula to have duplicates data
=IFERROR(SMALL(IF((csh"")*(ISNUMBER(csh))*(COUNTIF($B$3:B19,csh)=0),csh,""),1),IFERROR(INDEX(csh,SMALL(IF(SMALL(IF((COUNTIF($B$3:B19,csh)=0)*(ISTEXT(csh)),COUNTIF(csh,"<"&csh)+1,""),1)=IF((COUNTIF($B$3:B19,csh)=0)*(ISTEXT(csh)),COUNTIF(csh,"<"&csh)+1,""),ROW(csh)-MIN(ROW(csh))+1),1),MATCH(SMALL(IF((COUNTIF($B$3:B19,csh)=0)*(ISTEXT(csh)),COUNTIF(csh,"<"&csh)+1,""),1),INDEX(IF((COUNTIF($B$3:B19,csh)=0)*(ISTEXT(csh)),COUNTIF(csh,"<"&csh)+1,""),SMALL(IF(SMALL(IF((COUNTIF($B$3:B19,csh)=0)*(ISTEXT(csh)),COUNTIF(csh,"<"&csh)+1,""),1)=IF((COUNTIF($B$3:B19,csh)=0)*(ISTEXT(csh)),COUNTIF(csh,"<"&csh)+1,""),ROW(csh)-MIN(ROW(csh))+1),1),,1),0),1),""))
Goran,
read this:
Filter duplicate values, sorted and blanks removed (array formula)
Is there a version of this that works if the "tbl" is actually 3 different columns (non-consecutive)? I used the post "Extract a unique distinct list from three columns in excel," (https://www.get-digital-help.com/extract-a-unique-distinct-list-from-three-columns-in-excel/) but that formula does not remove blanks, which I need. Also, sorting alphabetically is not necessary.
Thanks!
Ross,
I have added an array formula that removes blanks:
Extract a unique distinct list from three columns with possible blanks
I'm using this code with Excel 2003 SP3 and i'm getting #NUM! in the fields where it should be blank.
The column where the content is being pulled from has been defined as a list (Property) and it also has data validation to pull information from a list in a different sheet so that the users can't input a "property" that isn't on the list.
Is this causing the #NUM! error in the distinct list? Is there a way around it?
Below is the modified code.
=INDEX(Property, SMALL(IF(SMALL(IF(COUNTIF($L$1:L1, Property)+ISBLANK(Property)=0, COUNTIF(Property, "<"&Property)+1, ""), 1)=IF(ISBLANK(Property), "", COUNTIF(Property, "0, "", COUNTIF(Property, "<"&Property)+1)), INDEX(IF(ISBLANK(Property), "", COUNTIF(Property, "<"&Property)+1), SMALL(IF(SMALL(IF(COUNTIF($L$1:L1, Property)+ISBLANK(Property)=0, COUNTIF(Property, "<"&Property)+1, ""), 1)=IF(ISBLANK(Property), "", COUNTIF(Property, "<"&Property)+1), ROW(Property)-MIN(ROW(Property))+1), 1), , 1), 0), 1)
darzon,
I am not sure if wordpress removed any "greater than" or "less than" signs from your code.
Here is what it should look like:
=INDEX(Property, SMALL(IF(SMALL(IF(COUNTIF($L$1:L1, Property)+ISBLANK(Property)=0, COUNTIF(Property, "<"&Property)+1, ""), 1)=IF(ISBLANK(Property), "", COUNTIF(Property, "<"&Property)+1), ROW(Property)-MIN(ROW(Property))+1), 1), MATCH(MIN(IF(COUNTIF($L$1:L1, Property)+ISBLANK(Property)>0, "", COUNTIF(Property, "<"&Property)+1)), INDEX(IF(ISBLANK(Property), "", COUNTIF(Property, "<"&Property)+1), SMALL(IF(SMALL(IF(COUNTIF($L$1:L1, Property)+ISBLANK(Property)=0, COUNTIF(Property, "<"&Property)+1, ""), 1)=IF(ISBLANK(Property), "", COUNTIF(Property, "<"&Property)+1), ROW(Property)-MIN(ROW(Property))+1), 1), , 1), 0), 1) The code above does not remove #NUM errors. I can´t create a formula that removes #NUM error in excel 2003. I have more than seven levels of nesting. If you upgrade to excel 2007 or later versions you can use IFERROR() function.
Thank you for writing this, it works like a charm!
However, there is one thing I would like to do different:
When I enter more entries in the array, the list updates with new entries in the order of first looking through the row, then going down the column. I would prefer the list first list the unique values in the column going downward, then then next column downward etc. Is that possible?
Thank you
Jonas,
See this file:
Unique-distinct-values-from-multiple-columns-using-array-formulas-jonas.xls
If the Range : tbl_num contains the numbers of :
Apple Banana Lemon
Orange Lemon Apple
Lemon Banana Orange
50 70 80
22 15 18
17 20 25
How to calculate the numbers of Apple , Banana , Lemon , Orange
Khaled Ali
Please explain in greater detail, what is the desired output?
[...] The answer is that there is no need for multiple duplicate columns in the array. Excel simplifies the array down to a single column. But when used with multiple cell ranges in more complicated array formulas, make sure the number of rows match. See this example: Unique distinct values from a cell range [...]
hi,
I want to know how to find out frequency of each word from a group of sentences.
Eg.
Amit is a good boy.
He works with XYZ.
Anil is good boy.
Here we have 3 sentences. Result should be something like this:
Amit -1
is - 2
a -1
good - 2
boy -2
He -1
Works -1
with - 1
XYZ -1
Please help me out to get this result. after looking your multiple post i thought i split sentences into different columns (txt to columns option with blank)and define tbl range and work accordingly but not getting proper results.
Please advise.
Thanks,
Amit
Amit,
read this post:
Excel udf: Word frequency
Thank you so much Oscar.
Regards,
Amit
Hello,
I know this formula works to create a unique list and it works extermely well. However, in my situation, I have some duplicate values in my range and I would actually like to create a list of all the values sorted. (if they are duplicates, they can just be listed twice or thrice). Would you be able to help me with that?
Thank You,
Harsh
Harsh,
Array formula:
=INDEX(tbl, SMALL(IF(SMALL(IF((COUNTIF(tbl, tbl)<=1)+ISBLANK(tbl)=0, COUNTIF(tbl, "<"&tbl)+1, ""), ROW(A1))=IF(ISBLANK(tbl), "", COUNTIF(tbl, "<"&tbl)+1), ROW(tbl)-MIN(ROW(tbl))+1), 1), MATCH(SMALL(IF((COUNTIF(tbl, tbl)<=1)+ISBLANK(tbl)=0, COUNTIF(tbl, "<"&tbl)+1, ""), ROW(A1)), INDEX(IF(ISBLANK(tbl), "", COUNTIF(tbl, "<"&tbl)+1), SMALL(IF(SMALL(IF((COUNTIF(tbl, tbl)<=1)+ISBLANK(tbl)=0, COUNTIF(tbl, "<"&tbl)+1, ""), ROW(A1))=IF(ISBLANK(tbl), "", COUNTIF(tbl, "<"&tbl)+1), ROW(tbl)-MIN(ROW(tbl))+1), 1), , 1), 0), 1) Get the Excel file extract-duplicates-sorted-alphabetically-removing-blanks-from-a-range.xls
Hello Oscar,
Thank you for your help! However, I think I was not clear in my earlier inquiry. What I meant to ask was i wan't a complete list of all the values in the array (not just the duplicates). and if banana exists twice in the array, then in the produced list banana would be listed twice. Would that be possible?
Thank You,
Harsh
Harsh,
Read this:
https://www.cpearson.com/excel/MatrixToVector.aspx
[…] As the name also implies, the data in G2:J14 is expected to be text with length > 0. Source. Unique distinct values from multiple columns using array formula | Get Digital Help - Microsoft Exce… The basic MATCH/COUNTIF has been attributed to Eero (a contributor at the now defunct MS […]
Is there way to modify this formula so it sorts by occurrence versus alphabetically?
Thank you for your assistance!
I should add descendingly.
I realize this is an old thread but its the closest I have been able to get to a solution for my problem. I am working with a data set spread across multiple sheets. I am pulling unique distinct a-z sorted values from a column with a single criteria. I am using a helper column on my "summary" sheet for each of the sheets I pull data from. I am then combining this into a unique distinct sorted list without blanks. The "summary" page is getting quite processor intensive with all the helper columns I am using. Is there a way to add a single criteria element to the formula? Basically a Unique distinct sorted list from two columns with a single criteria removing blanks?
Very useful material here. Thanks!
However, my range name is discontinuous (e.g. tbl = A1:A6 and C1:C6). It seems the formula does not work in this case.
Would e brilliant if it would work.
Marius
Marius,
Check out the Filter unique distinct values from multiple sheets add-in.
https://www.get-digital-help.com/how-to-extract-a-unique-list-and-the-duplicates-in-excel-from-one-column/#addin
It can use discontinuous ranges but unfortunately the add-in does not sort the values.
Hi Oscar, super tutorials as always.
Can you please update the formula to show blanks "" where iserror (to hide #NUM! cells)?
My application: I have 3 sheets with blanks and different abbreviations.
In a separate sheet I want to generate a Legend table (an alphabetic list of unique values, no blanks, dynamically updated).
I think this is a good start as a formula for my project.
Also, after having generated the "Legend" of all abbreviations used in those 3 sheets, I wish to have each abbreviation explained in the adjacent column (from an existing comprehensive list, which is defined as a named range).
Should a simple Vlookup do the trick?
Hi OP,
I have can see that this formula works well for the purpose its intended, how ever is it possible to replace #NUM! with a blank i.e. "". I tried the usual iserror method but it does not work is a array formula.
As there's been a few asking how to resolve same issue, I just thought I post my method, it involves a helper column I know.. I know) but at lease I was able to move on with the work I needed to do.
I created a the unique sorted list using the formula in this article, and next to it added a helper column that gave a true or false to the value in cell B8.
in Cell C8 I put in:
=IF(ISNONTEXT(B8)=TRUE,"",B8)
This will now list all test values sorted as I originally wanted.
I am interested in counting unique values across 8 columns in Excel that are not adjoining (i.e. AF, AN, AV, BD, BL, BT, CB, CJ). I have found functions to count in one or two columns but nothing for 8 and I cannot adapt them for my issue. Any suggestions?
Very helpful article - many thanks for posting the formula and the explanation. It did exactly as specified on the tin.
Great Formula! Thank You for posting and keeping it here.
Excellent Formula Oscar.
Hi,
I have more than 20 columns with true and false values. How do i get the names of top ten column with true values?
Hello Everyone,
Oscar, thank you for making this guide! I'm having some difficulty altering this formula to read a row of data. I figured I could replace instances of ROW( with COLUMN( but this is not working. Does anyone have any thoughts?
Thanks for the work on these formulas. I have this working on range over 6 columns, however I only need the unique values of data in this range if another column matches data entered into a cell.
This is a formula that worked for a single column (but not 6 columns)
=INDEX(WLDRI, MATCH(0, IF((PKG=$C$2),COUNTIF($R$2:R2,WLDRI), ""), 0))The key here is I want unique values returned for columns B3:G if column A3:A matches data in C2.
Thanks again.
Man you're awesome. Your formula work pretty soft. Something I would like to ask is wether you can give some piece of advice about how to learn Excel. Of course I have to practice utterly a lot, but you can tell me like certain steps (you have to start by this, and after that you have to do this, etcetera); something general (I would appreciate to you Mr Cronquist).
Take care
Regards
Sergio Bautista
In testing the formula shown in this article for "Extract a unique distinct list sorted alphabetically and ignore blanks from a range" shown below, I found that the formula breaks if you have more than 2 entries of numbers even though they're entered as '1, '2. As soon as you enter a third such value in the tbl, the next value repeats in the distinct list from that point to the end of the list array. If that can be solved, that is exactly what I need.
Thank you!!
=INDEX(tbl, SMALL(IF(SMALL(IF(COUNTIF($B$7:B7, tbl)+ISBLANK(tbl)=0, COUNTIF(tbl, "<"&tbl)+1, ""), 1)=IF(ISBLANK(tbl), "", COUNTIF(tbl, "0, "", COUNTIF(tbl, "<"&tbl)+1)), INDEX(IF(ISBLANK(tbl), "", COUNTIF(tbl, "<"&tbl)+1), SMALL(IF(SMALL(IF(COUNTIF($B$7:B7, tbl)+ISBLANK(tbl)=0, COUNTIF(tbl, "<"&tbl)+1, ""), 1)=IF(ISBLANK(tbl), "", COUNTIF(tbl, "<"&tbl)+1), ROW(tbl)-MIN(ROW(tbl))+1), 1), , 1), 0), 1) + CTRL + SHIFT + ENTER
Will this work with more columns and dynamic range (not named but using indirect)? I tried your new shorter formula in both Excel 2021 and Google Sheets, however, only a single value was listed. In Google Sheets, I placed the below formula in cell A3. Cell A1 contains the table's range which is $C$3:H. The table contains array formulas all on the 3rd row starting from col C. To be fair, this was also tested in Excel 2021, using the range on your first screenshot (B2:E5 or $B$2:$E$5) on A1, with static data instead of results of array formula, and pressing CTRL+SHIFT+Enter instead of using =ARRAYFORMULA(). What am I doing wrong and how do I adjust the formula to be able to accommodate a dynamic range if it doesn't handle it yet?
=ARRAYFORMULA(IFERROR(AGGREGATE(15, 6, INDIRECT(A1)/((COUNTIF($A$4:A4, INDIRECT(A1))=0)*(INDIRECT(A1)"")), 1), TEXTJOIN("", TRUE, IF(MIN(IF(SMALL(IF(ISTEXT(INDIRECT(A1))*(COUNTIF($A$4:A4, INDIRECT(A1)&"")=0), COUNTIF(INDIRECT(A1), "<"&INDIRECT(A1)), ""), 1)=IFERROR(COUNTIF(INDIRECT(A1), "<"&INDIRECT(A1))/ISTEXT(INDIRECT(A1)), ""), (ROW(INDIRECT(A1))+(1/(COLUMN(INDIRECT(A1))+1)))*1, ""))=(ROW(INDIRECT(A1))+(1/(COLUMN(INDIRECT(A1))+1)))*1, INDIRECT(A1), ""))))
Oscar, what worked for me is the formula from your newer post found in https://www.get-digital-help.com/extract-a-unique-distinct-list-sorted-alphabetically-removing-blanks-from-a-range-in-excel/ which is so much simpler than this solution but I tweaked it a bit to use "" instead of 0 for it to treat 0 as a value: =LET(x,SORT(UNIQUE(TOCOL(range))),FILTER(x,x""))