Unique/Distinct Dropdown List
Hi Shawn,
I've used the following rather long one-liner with good success.
It's an event code that builds a unique list from a master list, adding to
the unique list automatically as necessary.
Master list starts in A1, and can be as long as you like.
The unique list is created, starting at D2.
You can use the D2 list for your data validation drop-down source.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then Range(Cells(1, 1), Cells(Cells(Rows.Count,
1).End(xlUp).Row + 1, 1)).AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range("D2"), Unique:=True
End Sub
This forum window wraps the code, but it all goes on one line.
Perhaps you will find this useful.
Regards - Dave.
"Shawn" wrote:
Does anyone know of a way to create any type of dropdown list (i.e. Data
Validation List, Combo Box, etc.) which would contain a list of unique values
from a range of data? For example, if A5:A10 contained the names Mark, Larry,
Larry, John, Chris, John the dropdown would contain Mark, Larry, John, Chris.
One solution I thought of was to use one of the various methods (autofilter,
array, UDF) to first create the unique list, then use the unique list as the
range for the dropdown list, but I was wondering if it was possible to skip
creating the unique list first and have it appear only in the dropdown.
I am open to excel formulas or VBA. Let me know if anyone has any ideas.
|