Use a drop down list to extract and concatenate unique distinct values
Question: Is there a way to have a unique list generated from a list? Meaning I have a sheet that contains my data and I want to generate a drop down list based on the input from one column. Which I already have.
Once the user selects the value from the drop down, I want it to generate another unique list just in a column.
For example: the sheet contains store numbers (one column) and employee names (a second column), which may be listed multiple times. I want to create the drop down for the store number and then creating a list of employee names (non-repeating) that isnt a drop down, just a standard list is say A1,A2,A3,A4,etc
Is that clear as mud?
Thanks.
Answer:
This workbook contains:
- Array formula (Sheet: Data) sorts and filters unique distinct store numbers
- Named range: UniqueStoreNumbers =Data!$E$2:$E$27
- Drop down list (data validation) (Sheet: Sheet1)
- Custom function: Concat_Unique (Sheet: Sheet1)
- Sheets: Sheet1 and Data
Sheet: Data
Array formula in cell E3:
How to create an array formula
- Select cell E3
- Paste formula
- Press and hold Ctrl + Shift
- Press Enter
How to copy array formula
- Select cell E3
- Copy cell (not formula)
- Select cell range E4:E29
- Paste
Create a named range
- Go to tab "Formulas"
- Click "Name Manager" button
- Click "New.."
- Type UniqueStoreNumbers
- Select cell range =Data!$E$2:$E$27 in Refers to:
- Click OK!
Sheet: Sheet1
Create drop down list
- Select cell A2
- Go to tab "Data"
- Click "Data validation.." button
- Go to tab "Settings"
- Select List in Allow: field
- Type in source: field: =UniqueStoreNumbers
- Click OK
Add vba code to module
- Copy vba code below
- Press Alt+F11
- Right click on workbook in project explorer
- Select Insert and Module
- Paste vba code to code module
- Return to excel
Vba code
Function Concat_Unique(Lookup_Value As String, Lookup_Column As Range, Concat_column As Range)
Dim i As Single
Dim Unique As New Collection
Dim Value As Variant
Dim result As String
For i = 1 To Lookup_Column.Cells.Rows.Count
If Lookup_Value = Lookup_Column.Cells(i).Value Then
If Len(Concat_column.Cells(i)) > 0 Then
On Error Resume Next
Unique.Add Concat_column.Cells(i), CStr(Concat_column.Cells(i))
On Error GoTo 0
End If
End If
Next i
For Each Value In Unique
result = result & Value & ", "
Next Value
If Len(result) = 0 Then
Concat_Unique = ""
Else
Concat_Unique = Left(result, Len(result) - 2)
End If
End FunctionFormula in cell B2:
Copy cell B2 and paste to cell range B3:B8.
Download excel *.xlsm file
Related posts:
Use filtered table values in a drop down list (vba)
Extract dates using a drop down list in excel
Create dependent drop down lists containing unique distinct values in multiple rows
Create dependent drop down lists containing unique distinct values in excel




















I am trying to create an estimating form that will calculate a total cost based of the values given. I have a drop down list, and i want it to produce a $ value for each item in a different cell. My goal is to create a form that will calculate total values.
Hi,
I had a question. I have a excel costing sheet. What it is is a pull down menu with options to build a trailer.
So one pull down menu is tires. Then i pull down and it has a bunch of different tire options. My question is how do i get the price to change when i select different tires?
There are 3 tires. Goodyear is 500.00 RM is 400 and DL is 800.00
so i go to the pull down menu and choose a tire then i need the correct price to go in the price box beside that. I have aformula to do this but it's so long and i think it can be alot easier.
Right now this is the formula:
=IF(A51="X",VLOOKUP(B51,Sheet1!$A$2:$B$12001,2,FALSE),"-")
BUT what it does is look up on one sheet who gets its information from another sheet who gets its information from another sheet. So there are all these sheets and im pretty sure i don't need them all. It's just making this spreadsheet very large and very slow!
Please help if you can
Aynsley,
Your formula seems to be fine.
yes, i know my formula is fine but i think it requires way too much work to do something that seems fairly simple.
it takes it's information from the options work sheet. which looks the price up on the price worksheet which looks it up on another work sheet to get the inforamtion.
it just seems like something could be cut somewhere.