## Create a drop down list containing only unique distinct alphabetically sorted text values using excel array formula

**Question:**

How do I create a drop down list with unique distinct alphabetically sorted values?

**Answer: **

**Table of contents**

### Sort values using array formula

**Array formula in cell B2**

**How to create an array formula**

- Select cell B2
- Type above array formula
- Press and hold Ctrl + Shift
- Press Enter once
- Release all keys

**How to copy array formula**

- Select cell B2
- Copy (Ctrl + c)
- Select cell range B3:B6
- Paste (Ctrl + v)

### Explaining array formula in cell B2

=INDEX(List, MATCH(0, IF(MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))=(COUNTIF(List, ">"&List)+1), 0, 1), 0))

**Step 1 - Convert text to numbers**

=INDEX(List, MATCH(0, IF(MAX(NOT(COUNTIF($B$1:B1, List))*(**COUNTIF(List, ">"&List)+1**))=(COUNTIF(List, ">"&List)+1), 0, 1), 0))

COUNTIF(range,criteria) counts the number of cells within a range that meet the given condition

COUNTIF(List, ">"&List)+1

becomes

COUNTIF({"DD";"EE";"FF";"EE";"GG";"BB";"FF";"GG";"DD";"TT";"FF";"VV";"VV";"FF"}, ">"&{"DD";"EE";"FF";"EE";"GG";"BB";"FF";"GG";"DD";"TT";"FF";"VV";"VV";"FF"})+1

becomes

{11;9;5;9;3;13;5;3;11;2;5;0;0;5}+1

becomes

{12;10;6;10;4;14;6;4;12;3;6;1;1;6}

**Step 2 - Identify previous unique text values above current cell**

=INDEX(List, MATCH(0, IF(MAX(**NOT(COUNTIF($B$1:B1, List))***(COUNTIF(List, ">"&List)+1))=(COUNTIF(List, ">"&List)+1), 0, 1), 0))

COUNTIF(range,criteria)** c**ounts the number of cells within a range that meet the given condition

NOT(COUNTIF($B$1:B1, List))

becomes

NOT(COUNTIF("Unique list sorted alpabetically", {"DD";"EE";"FF";"EE";"GG";"BB";"FF";"GG";"DD";"TT";"FF";"VV";"VV";"FF"}))

becomes

NOT({0;0;0;0;0;0;0;0;0;0;0;0;0;0})

becomes

{1;1;1;1;1;1;1;1;1;1;1;1;1;1}

**Step 3 - Calculate maximum number in array**

=INDEX(List, MATCH(0, IF(**MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))**=(COUNTIF(List, ">"&List)+1), 0, 1), 0))

MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))

becomes

MAX({1;1;1;1;1;1;1;1;1;1;1;1;1;1}*({12;10;6;10;4;14;6;4;12;3;6;1;1;6})

and returns 14.

**Step 4 - Convert maximum number into Boolean value**

=INDEX(List, MATCH(0, **IF(MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))=(COUNTIF(List, ">"&List)+1), 0, 1)**, 0))

IF(MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))=(COUNTIF(List, ">"&List)+1), 0, 1)

becomes

IF(14={12;10;6;10;4;14;6;4;12;3;6;1;1;6}, 0, 1)

and returns this array:

{1;1;1;1;1;0;1;1;1;1;1;1;1;1}

**Step 4 - Return the relative position of an item in an array**

=INDEX(List, **MATCH(0, IF(MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))=(COUNTIF(List, ">"&List)+1), 0, 1), 0)**)

MATCH(lookup_value;lookup_array; [match_type]) returns the relative position of an item in an array that matches a specified value

MATCH(0, IF(MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))=(COUNTIF(List, ">"&List)+1), 0, 1), 0)

becomes

MATCH(0, {1;1;1;1;1;0;1;1;1;1;1;1;1;1}, 0)

and returns value 6.

**Step 5 - Return a value of the cell at the intersection of a particular row and column**

INDEX(array,row_num,[column_num]) returns a value or reference of the cell at the intersection of a particular row and column, in a given range

=INDEX(List, MATCH(0, IF(MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))=(COUNTIF(List, ">"&List)+1), 0, 1), 0))

becomes

=INDEX(List, 6)

becomes

=INDEX({"DD";"EE";"FF";"EE";"GG";"BB";"FF";"GG";"DD";"TT";"FF";"VV";"VV";"FF"}, 6)

and returns value BB.

**Create a dynamic named range**

- Click "Formulas" tab
- Click "Name Manager"
- Click List
- Type =OFFSET(Sheet1!$A$2, 0, 0, COUNT(IF(Sheet1!$A$2:$A$1000="", "", 1)), 1) in "Refers to:" field.
- Click "Close" button

**Named range**

List (dynamic)

What is named ranges?

**How to create a drop down list with values updated dynamically in excel 2007**

- Click Data tab
- Click Data validation button
- Click "Data validation..."
- Select List in the "Allow:" window. See picture below.
- Type =OFFSET($B$2, 0, 0, COUNT(IF($B$2:$B$1000="", "", 1)), 1) in the "Source:" window
- Click OK!

**Download example workbook**

Create-a-drop-down-list-containing-only-unique.xls

(Excel 97-2003 Workbook *.xls)** **

Functions in this article:

Functions in this article:

**IF(**logical_test;[value_if:true];[value_if_false]**)
**Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE

**INDEX(**array,row_num,[column_num]**)**

Returns a value or reference of the cell at the intersection of a particular row and column, in a given range

**SMALL(**array,k**)** returns the k-th smallest row number in this data set.

**ROW(**reference**)** returns the rownumber of a reference

**MATCH(**lookup_value;lookup_array; [match_type]**)**

Returns the relative position of an item in an array that matches a specified value

**COUNTIF(**range,criteria**)**

Counts the number of cells within a range that meet the given condition

**COUNT(**value1;[value2]**)
**Counts the number of cells in a range that contain numbers

**OFFSET(**reference,rows,cols, [height],[width]

**)**

Returns a reference to a range that is a given number of rows and columns from a given reference

### Sort values using vba

**Array formula in cell B2:B8000:**

**How to create array formula**

- Select cell range B2:B8000
- Type array formula above
- Press and hold Ctrl + Shift
- Press Enter once
- Release all keys

**VBA code**

You can find the selectionsort function here: Using a Visual Basic Macro to Sort Arrays in Microsoft Excel

Function FilterUniqueSort(rng As Range) Dim ucoll As New Collection, Value As Variant, temp() As Variant ReDim temp(0) On Error Resume Next For Each Value In rng If Len(Value) > 0 Then ucoll.Add Value, CStr(Value) Next Value On Error GoTo 0 For Each Value In ucoll temp(UBound(temp)) = Value ReDim Preserve temp(UBound(temp) + 1) Next Value ReDim Preserve temp(UBound(temp) - 1) SelectionSort temp FilterUniqueSort = Application.Transpose(temp) End Function Function SelectionSort(TempArray As Variant) Dim MaxVal As Variant Dim MaxIndex As Integer Dim i, j As Integer ' Step through the elements in the array starting with the ' last element in the array. For i = UBound(TempArray) To 0 Step -1 ' Set MaxVal to the element in the array and save the ' index of this element as MaxIndex. MaxVal = TempArray(i) MaxIndex = i ' Loop through the remaining elements to see if any is ' larger than MaxVal. If it is then set this element ' to be the new MaxVal. For j = 0 To i If TempArray(j) > MaxVal Then MaxVal = TempArray(j) MaxIndex = j End If Next j ' If the index of the largest element is not i, then ' exchange this element with element i. If MaxIndex < i Then TempArray(MaxIndex) = TempArray(i) TempArray(i) = MaxVal End If Next i End Function

**Where to copy vba code?**

- Press Alt + F11
- Insert a module into your workbook
- Copy (Ctrl + c) above code into the code window

**Download excel 97-2003 *,xls file**

### 71 Responses to “Create a drop down list containing only unique distinct alphabetically sorted text values using excel array formula”

### Leave a Reply

**How to add vba code to your comment:**

[vb 1="vbnet" language=","]

your code

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org

Add picture link to comment.

**Contact Oscar**

You can contact me through this webpage

I encountered an issue when using Excel 2007 where upon saving the workbook as an Excel Workbook (not 97-2003) the embedded count(if( ...)) formula causes only the first item in the drop down list to appear. This only happens upon opening the workbook and if you select data validation on the cell the issue is resolved. However, upon saving and reopening the problem reappears. The only workaround if to either remove the function or keep the workbook in 97-2003 format.

For a workaround in excel 2007, you can use the following in the "Refers to:" field under the name manager: =OFFSET($B$2, 0, 0, COUNTIFS($B$2:$B$1000,"",$B$2:$B$1000,"#N/A"), 1)

<

Sorry, it got coruppted. Here is the correct one: For a workaround in excel 2007, you can use the following in the "Refers to:" field under the name manager: =OFFSET($B$2, 0, 0, COUNTIFS($B$2:$B$1000,"<>",$B$2:$B$1000,"<>#N/A"), 1)

Sorry again. Use the above furmula for the data validation. NOT for the name manager.

Josh, thanks for bringing this to my attention. I´ll try to solve this issue.

I want the drop down box to be on a different worksheet. But EXCEL won't allow OFFSET without having it all on one worksheet.

Is there some other way to have the lists on one sheet, get unique values and sort them, then reference them from a drop down on another worksheet? To make matter more fun, I need the ranges to be dynamic as the user may be adding new records.

Thanks!

Dianne

I have re-created the above formula but would like to create a range that is larger than the current data so that the unique list picks up all new data. Currently my unique list repeats the last line of data several times because the range name extends beyond it. Can this be done?

Thanks

Keels

Dianne,

I want the drop down box to be on a different worksheet. But EXCEL won't allow OFFSET without having it all on one worksheet.It is not OFFSET, it is Data Validation that won´t allow having it all on one worksheet.

But there is a workaround, if you create another named range (for example, named unique) and type =OFFSET(Sheet1!$B$2, 0, 0, COUNT(IF(Sheet1!$B$2:$B$1000="", "", 1)), 1).

Create a drop down box on another sheet and type =unique in "source:"

To make matter more fun, I need the ranges to be dynamic as the user may be adding new records.I have updated the post, the named range is now dynamic.

Keels,

I have re-created the above formula but would like to create a range that is larger than the current data so that the unique list picks up all new data. Currently my unique list repeats the last line of data several times because the range name extends beyond it. Can this be done?I have updated this post, the named range is now dynamic.

This is almost exactly what I have been looking for. The only shortcoming is that I need it to work with spaces (empty cells) in the source list and able to handle a source list that is only one item. I want the person to begin to fill out a column (the source list) filling in names and as they go they can instead pick from a drop down menu so they do not have to type the name (and so the name is always the same). When they type the first name in, it does not appear in the list. Only when they type the second name, then both names appear. Can this be fixed? They are allowed to skip rows filling out the table, so handling blank cells is important too. Thank you.

Peter,

Array formula to remove blanks in blog post example:

=INDEX(List, MATCH(0, IF(MAX((COUNTIF($B$1:B1, $A$2:$A$15)=0)*(($A$2:$A$15<>"")*(COUNTIF($A$2:$A$15, ">"&$A$2:$A$15)+1)))=(IF(($A$2:$A$15<>""), COUNTIF($A$2:$A$15, ">"&$A$2:$A$15)+1, "")), 0, ""), 0)) + CTRL + SHIFT + ENTER

I dont´t understand this:

I want the person to begin to fill out a column (the source list) filling in names and as they go they can instead pick from a drop down menu so they do not have to type the name (and so the name is always the same). When they type the first name in, it does not appear in the list. Only when they type the second name, then both names appear. Can this be fixed?That revised formula worked perfectly. It solved both the problem with spaces interspersed in the source list and the diminutive situation with only one item in the source list (yielding a one item menu). I can't see any reason someone would not prefer this revised equation over the original. I would update your example above to use this formula instead.

As for my explanation as to what I am doing..... sorry that was clear as mud....

I want a column of data entry cells on a form that allows either free form text entry or a dynamic drop down menu of the items the person already typed into that same column. This way they don't have to "type" the same name twice (can pick it from the menu the second time). It makes data entry faster and increases the likely hood that multiple duplicate entries will be the exact same. To allow text entry at the same time as menu selection, I just turn off the data validation error message.

Over time I may build a dynamic list of names from past times the form was filled out so that this drop down menu does not start out blank each time. But right now this is still helpful to the user (and me).

Thank you very much.... I have yet to figure out how all these complex array formulas work. Right now you are the magician and I am the kid in awe.

Peter,

Maybe you can use these instructions:

Excel Data Validation -- Hide Previously Used Items in Dropdown and modify formulas to only show previously used items in a drop down list.

Thanks Oscar,

That might come in handy some day. In the process of scoping that out I stumbled on a bunch of other potentially useful data validation methods including selecting multiple items from a menu.

"If God didn't invent Excel, I bet that's where he spends most of his time." - Peter V.

This is really good; thanks for posting.

Chris,

thank you!

may i ask the maximum limit on the amount of records you can have in a dropdown list?

thanks.

Juna,

I can´t enter more than 32767 values in a drop down list in excel 2007.

Maybe someone else can shed some light on this, I can´t find anything about this (google).

tnx oscar for this formula

but i have a problem with that.

it has to calculate about 8000 cells and it slows down my pc badly.

any suggestions?

luka,

I have updated this article with a vba function. Download the attached file!

Hi

The dropdown unique listing is really helpful and i appreciate that.

Eddy Stanley,

Thanks!

Hi,

I have a requirement (read problem). I have created a drop down list with following items:

1.Above

2.Below

3.At par

I want if someone choose Above, a formula for escalation of value is executed, if Below a formula for Degradation of value, if At par is used no change in the value.

I am unable to link the chosen field in formula.

Kindly help.

Thanks

DJ,

I am not sure that is possible. What is the formula for escalation of a value?

I would suggest a spin button (form control) and link the control to a cell.

I have a problem if in Column A i have only one value 'DD' (means A1 as List and A2 as DD) then no value are coming in column B using

=INDEX(List, MATCH(0, IF(MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))=(COUNTIF(List, ">"&List)+1), 0, 1), 0))

Can u plz give me the fix to it. I am also trying but not sure about it.

This is urgent..

Nidhi,

For some reason that I don´t understand, the dynamic named range used in a function returns an error when the

Listcontains a single value.I am not sure how to resolve this, maybe you can use a - or # character in the first cell and "DD" in the second cell?

Oscar,

Great work and a huge time saver!!! Thank you.

[quote]For some reason that I don´t understand, the dynamic named range used in a function returns an error when the List contains a single value.[/quote]

It has to do with the way Excel evaluates expressions. When you have only one value, Excel reduces the expressions for the "range" inside of Match as a single unique value, rather than a range of values with only one element in it. Since Match expects its second argument to be a range, then it throws the error.

Example:

The way we'd like Excel to evaluate the "Match" expressions would be:

=MATCH(0, {0},0)

Instead, Excel evaluates it as (note the second argument is plainly "0", a number, and not the array {0}:

=MATCH(0, 0,0)

To correct this, one can force Excel to calculate the result of the "if" as an array, as follows (note the "{0}+" part):

=INDEX(List,MATCH(0,{0}+IF(MAX(NOT(COUNTIF($B$1:B1,List))*(COUNTIF(List,">"&List)+1))=(COUNTIF(List,">"&List)+1),0,1),0))

Hope this helps

Mijael,

Thanks for your valuable contribution!

Another, "one-row-code", VBA tip:

!!! Only be aware, that the value from the first line will be taken as the title.

Palo

Thank you so much Oscar. This is really great esp. the explanation of the formulae !

Many thanks for the COUNTIF trick, Oscar. This helps me a lot.

I would change it in a shorter formula, and it works.

=INDEX(List, MATCH((COUNTIF(List, ">"&List)+1), MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1), 0))

If the data contains all numbers, I will use rank(list,list) to replace (COUNTIF(List, ">"&List)+1)

=INDEX(List, MATCH(RANK(List,List), MAX(NOT(COUNTIF($B$1:B1, List))*RANK(List,List), 0))

sorry, I made a mistake.

I would change it in a shorter formula, and it works.

=INDEX(List, MATCH(MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1)), (COUNTIF(List, ">"&List)+1), 0))

If the data contains all numbers, I will use rank(list,list) to replace (COUNTIF(List, ">"&List)+1)

=INDEX(List, MATCH(MAX(NOT(COUNTIF($B$1:B1, List))*RANK(List,List)), RANK(List,List), 0))

[...] Names -- Excel Named Ranges Excel Magic Trick # 259: Dynamic DV List Based On DV List - YouTube Create a drop down list containing only unique distinct alphabetically sorted text values using exce... I hope these help and good luck with your project. [...]

[...] OFFSET or Table Feature? - YouTube excelisfun -- Excel How To Videos - YouTube Or here.... Create a drop down list containing only unique distinct alphabetically sorted text values using exce... For Question 2, you can concatenate (join) your two cells and use a Conditional Formatting [...]

Dear Oscar,

Can you help me to get the values of Unique distinct list sorted alphabetically in horizantally instead of vertical by using VBA fuction. Kindly find the eclosed Excel sheet obtained from your website.

Thanks

Sudhakar

Sudhakar,

Mr. Oscar

Thanks for your great help,

cheers...

Sudhakar

Hi. talking about duplicates, I have a problem with that.

I have two arrays to compare and highlight duplicates, I already try -countif conditional formatting-, -index match-, =and, and nothing work my arrays are Number one is A1:F53 and Number two H1:M53 as a little illustration here you are.

10-11-12-17-28-46 against 2-10-11-41-42-53

03-09-11-21-24-49 against 3-13-42-47-52-53

thanks.

vicktor schausberger,

Here is an example:

Conditional formatting formula:

=COUNTIF($C$1:$C$6,A1)

applied to cell range A1:A6. Make sure you get the relative and absolute cell references correct. Don´t forget to pick a formatting fill color.

thanks Oscar. I was looking to avoided absolute cells, I am working by rows, not by columns. by the way, how can I load up a partial spreadsheet in you forum, so I can make clear myself.

Thanks Oscar.

vicktor schausberger,

You can upload your file here.

Marvelous work, and thank you! I would like to explain what worked for me and what did not, and ask two questions. First I tried Oscar's original, Mijael's, and Zarc Lee's versions - but I was trying to create the "B2" column on a separate sheet. Result: only the first item of the list showed up in each line.

Second, I tried all three on the same page as the column to be summarized. All worked and produced identical results. In each case the last item of the list is repeated in extra cells; the destination list must be trimmed manually.

Question: Is there a way to have the list (a Table in my case, with a named dynamic range inside it to be used for data validation) set it's size automatically to the number of unique items it contains? The reason I ask, is that the document I am creating may be passed on for use to less experienced users, and I'd like to make it as "idiot-proof" as possible (not that anyone's an idiot for not understanding the minutiae of Excel...). Also, is it possible to make these formulas work on a separate sheet. I would like to have all 20 of my "unique" lists located together on a single sheet, instead of across the 20 original sheets. I apologize in advance if the answers are here and I missed them.

Don Quixote,

but I was trying to create the "B2" column on a separate sheet. Result: only the first item of the list showed up in each line.It seems that you have entered the array formula in all cells simultaneously. Enter it in one cell. Press CTRL + SHIFT + ENTER. Copy the cell and paste it to the cells below. There are relative cell refs in the formula and they don´t work if you enter the formula in all cells.

Is there a way to have the list (a Table in my case, with a named dynamic range inside it to be used for data validation) set it's size automatically to the number of unique items it contains?No, as far as I know. You need a helper column.

I would like to have all 20 of my "unique" lists located together on a single sheet, instead of across the 20 original sheets.Sheet2 contains two example "unique" lists. They return values from sheet1. There are also two drop down lists that uses a formula and a named range to get the values from "unique" list on sheet1.

Download excel *.xlsx file

Create-a-drop-down-list-containing-only-unique-distinct-valuesv3.xlsx

Hi Don Quixote,

I apologize I'm not posting code right now, but I'm away from a computer. I hope these general ideas help you a bit.

You can try playing with named ranges. The key to the end result will be to use Offset to resize the resulting range, and one of the countxxx formulas (depending on what suits your data better), in order to get the proper number of rows in the resulting range. Once you calculate this as a named range, you can simply use data validation->list = in order to populate the dropdowns.

On the other hand, at this point the formulas start to be complicated enough, and you mentioned you want several of these lists. Honestly, I believe it would be much simpler, fast, and user-proof to use the VBA code supplied by Oscar. You can tweak it so another macro calls Oscar's to create all of your ranges at any point, or in response to any event you'd like. As an additional tip, you can define a set of constants in your VBA code to define the colums you want to read from and cells you want to write to. This way, you avoid over-complicating the code for the lists, and still retain flexibility for when you want to add columns in your tables, change the order, etc.

Happy coding!

Ups! It seems I wrote an invalid HTML tag after the "=" sign. What I meant to write is:

list = [my_named_range].

Sorry.

Thanks Mijael, in the first sheet I created (manually) adjusting the named ranges works fine. Unfortunately, I'm inept with VBA (maybe 6-12 months from now I'll have a grasp), and when I ran Oscar's code it glitched, so no UDF.

Unfortunately, I won't be able to get much further at the moment - I'm having to backtrack along revisions. Three revisions (to other parts of the workbook) down the line, the formula suddenly fails - when the original list is modified it will no longer cope with blanks - it eliminates the final member of the series in the "unique" range and subsequent fields yield "0" instead of replicas of the last member of the list. The only way to un-glitch it is to fill in all the blanks. Going back several revisions though, as I said, the original still works fine whatever I do to it. Can't imagine what I did on another sheet(s) that could effect the performance of this formula on this sheet. Ah, well... 2 steps forward, 1 back, repeat.

p.s. Upon further investigation, the original formulas fail in exactly the same manner when the second item in the A column (raw data) is blank.

p.p.s. Also fails in the same manner when the last item in the raw data list is/would be the last item alphabetically in the unique list. But maybe it's just because it's Mardi Gras here in New Orleans and cold & rainy. Bad ju ju.

Final conclusion: this formula cannot truly handle blanks. It would take hundreds of words to describe exactly what it produces under what circumstances. Bottom line is it always works for alphabetizing and removing duplicates; and _sometimes_ handles blanks. Good enough for my purposes, as it turns out. I guess it's VBA for the next step! Cheers,

Hi Don Quixote!

I'm curious as to why it fails when you have blanks. Can you upload a copy of the spreadsheet with glitches? My initial guess is that COUNTIF returns #N/A when it compares a blank cell v.s. anything else, in which case you might need to substitute COUNTIF with some form of SUM(IFERROR(...)); let me test it and I'll post it.

[…] the references I have been using this formula for a few years now. The author of this formula is Create a drop down list containing only unique distinct alphabetically sorted text values using exce… […]

Sorry I've tried to send this few times but has problem, if you see the spam please ignore...

Hi Oscar, Your steps are very clear and good but I have problem when the cells in list is blank or so call ="", I tried to change it to =" " it works better but the last item will always missing.

i.e.

A1=" "

A2=" "

A3=350

A4=" "

A5=750

A6=450

A7=1700

A8=1700

A9=2000

"2000" will be missing in the sorted list, can you tell me what to deal with this? Thank you.

CSLeong,

My guess is that something wrong with your named range.

I'm trying to use this to sort and return unique values for a named range with two columns. For test purposes say OneList=$A$2:$B$21. The sorted unique list should end up in "F".

I tried:

=INDEX(OneList,MATCH(0,IF(MAX(NOT(COUNTIF($F$1:$F1,OneList))*(COUNTIF(OneList,">"&OneList)+1))=(COUNTIF(OneList,">"&OneList)+1),0,1),0),1)

It works if I change "OneList" to only one column. But, with "OneList" having two columns and with the "1" at the end for the [column_num] it throws a "#N/A".

Ultimately, I was going to sorta brute force it by wrapping the formula in an "IFERROR()" using "1" and then cascading to "2". But, it fails when I tried the "1" so I haven't gotten that far.

Great site. I've learned lots but also learned I've got a lot more to learn.

Hi Emil,

Would concatenating columns A and B into a third column (say, column C) work for you? This way, you can use the methods here on column C, and you will get the unique values.

Actually, you don't even need the third column I suggested; you can keep using named ranges (my "TowColumnList" is your "OneList"):

LeftList

=OFFSET(TwoColumnList,0,0,ROWS(TwoColumnList),1)

RightList

=OFFSET(TwoColumnList,0,1,ROWS(TwoColumnList),1)

concatList

=CONCATENATE(LeftList, ", ", RightList)

Then use concatList to create the sorted unique list.

I created "Left" and "Right" lists to simplify changing the order of the concatenation, but you can use their definitions directly on that of concatList if you prefer. I also added a comma and a space (", ") in case you later wanted an easy way to separate the concatenated values again, but this is also optional.

Hope this helps.

Mijael,

Thanks for the suggestion.

I created the "LeftList", "RightList", and "concatList" off of the "OneList" as you show Mijael and I can use the "LeftList" and "RightList" in "=INDEX(LeftList,15)" or "=INDEX(RightList,15) (for example) functions as a test of the lists, but the "concatList" list does not work in the "=INDEX(concatList,25)" function or in the formula on the top of this page. I tried the ,", ", and ,"; ", in the CONCATENATE formula.

I get a "#REF!" error in the INDEX function and a "#N/A" error in the formula from this page.

Were you able to "CONCATENATE" two named ranges together as you show? I didn't think it was possible to UNION or JOIN two named ranges together like that.

Further testing revealed that "=INDEX(concatList,18)" gives me:

the 18th item in the LeftList", "the 18th item in the RightList

Without the "s of course. Not what I was expecting! but, interesting. It also explains why I get the error for "=INDEX(concatList,25)", it thinks there are only 20 elements in "concatList".

I really need the "UNION" of the two lists but I can accept the "JOIN" of the two lists and then use the formula from this page to get only the distinct elements of both lists.

I tried defining a list as "=Sheet1!$A$2:$A$21,Sheet1!$B$2:$B$21" but for "INDEX" it returns only the first 20 items and throws an error for any "INDEX" function greater than 20. I created this by using the ctrl key to select non-contiguous ranges. I really thought this would work.

Oscar, awesome formula, even the one that doesnt sort alphabetically.

This array (the alphabetical one) duplicates the last value.

For example I paste the formula down 11 rows, since there are only 3 unique values it just duplicates the last one till it filled the 11 rows.

Example Results.

2014-06 JUN

2014-07 JUL

2014-08 AUG

2014-08 AUG

2014-08 AUG

2014-08 AUG

2014-08 AUG

2014-08 AUG

I need the other rows to be empty.

Please help.

Thijs,

Check out the attached file, sheet2.

Create-a-drop-down-list-containing-only-unique3.xlsx

Hey Oscar, the formula works, but when I replace your $A$2:$A$12 to my dynamic name range it duplicates the last month.

So this works:

=IFERROR(INDEX($A$2:$A$12,MATCH(0,IF(MAX(NOT(COUNTIF($B$1:B1,$A$2:$A$12))*(COUNTIF($A$2:$A$12,">"&$A$2:$A$12)+1))=(COUNTIF($A$2:$A$12,">"&$A$2:$A$12)+1),0,1),0)),"")

This does not work:

=IFERROR(INDEX(MyDynamicRange,MATCH(0,IF(MAX(NOT(COUNTIF($B$1:B1,MyDynamicRange))*(COUNTIF(MyDynamicRange,">"&MyDynamicRange)+1))=(COUNTIF(MyDynamicRange,">"&MyDynamicRange)+1),0,1),0)),"")

So my guess is there is an issue with my dynamic named range:

=OFFSET('Test Data Tab'!$W$2,0,0,COUNTA('Test Data Tab'!$W:$W))

I update my data daily, so my W column keeps adding up, I can not limit it to $W$2:$W$100, hence me using $W:$W

Any ideas?

Oscar,

Loving this.

I'm working on unsorted tables that list Employees, manager level 1, manager level 2, along with other data, each in seperate columns.

I'm trying to use your VBA script to programatically remove the superfluous & sort my raw data hierarchally & alphabetically.

--- Examble Raw ---

Manager A level 2, Manager A level 1, Employee AA, other stuff

Manager A level 2, Manager B level 1, Employee BA, other stuff

Manager A level 2, Manager A level 1, Employee AB, other stuff

Manager A level 2, Manager B level 1, Employee BB, other stuff

--- End Raw ---

--- Examble Sorted ---

Manager A level 2, Manager A level 1, Employee AA, other stuff

Manager A level 2, Manager A level 1, Employee AB, other stuff

Manager A level 2, Manager B level 1, Employee BA, other stuff

Manager A level 2, Manager B level 1, Employee BB, other stuff

--- End Sorted ---

I'm using some helper columns, with the FilterUnigueSort on another sheet to build my hierarchy of the 2 different manager levels.

When pasting the FilterUniqueSort array into my helper column I get a number of cells at the bottom of the list that produce "#N/A" results.

Could you please advise of modifications after the "selectionsort temp" I could add so that instead of "#N/A" I get blanks regardless of how many rows I paste my array into.

i.e.

15000 rows of raw data

20 level 2 Managers

filteruniquesort pasted into 30 rows in helper column would result in 20 sorted managers & 10 blank fields.

Thank you for your consideration.

hallo Oscar i am using the

http://cdn.get-digital-help.com/wp-content/uploads/2009/05/Create-a-drop-down-list-containing-only-unique_vba.xls

aplication and i wonder if it,s possible to adjust the vba code

so results wil show directly in alphabetic order

thanks in advance greatings Tobo

sorry i was a little confused i thought id dit not sort properly

but it also sorts in capital (first) letter so the word Zulo

with capital Z wil end up as first entry

is there a way to Change that?

Zulo

alpha

beta

charly

delta

how can i enter index match Array Formula in data validation dropdown list because i need it in 1000 number of rows and want to match three columns in each row.

[…] Create a drop down list containing only unique distinct alphabetically sorted text values using exce… […]

I cannot get the VBA code to run in excel 2010. I just lists the first item in the range over and over. Your downloaded spreadsheet runs in the compatibility mode fine.

Thanks in advance

-Ben

Solved!

I did not follow instructions to select the cell range and input the formula. I put the formula in the first cell and copied it down which did not work. YOU MUST SELECT THE CELL RANGE!

How can you get rid of the #N/A from the vba when no further matches are found...

NFN ned

=IFERROR(INDEX(List, MATCH(0, IF(MAX(NOT(COUNTIF($B$1:B1, List))*(COUNTIF(List, ">"&List)+1))=(COUNTIF(List, ">"&List)+1), 0, 1), 0)), "")

Note, the IFERROR traps and handles all errors in a formula.

https://support.office.com/en-us/article/IFERROR-function-c526fd07-caeb-47b8-8bb6-63f3e417f611