Hello Gary,
Here is another method. This macro loads a Drop Down by name with only the unique values from the range specified. Place this code in a Standard VBA Module.
'Written: August 18, 2007
'Author: Leith Ross
'Summary: Loads the named Forms Drop Down control with only unique values
' from the specified range.
Sub LoadUniquesInDropDown(Rng As Range, Drop_Down As Excel.DropDown)
Dim Cell As Range
Dim Data()
Dim N As Long
Dim SortRmg As Range
Dim Wks As Worksheet
Set Wks = Rng.Parent
Rng.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Set SortRng = Rng.SpecialCells(xlCellTypeVisible)
Wks.ShowAllData
For Each Cell In SortRng
ReDim Preserve Data(N)
Data(N) = Cell
N = N + 1
Next Cell
With Drop_Down
.RemoveAllItems
.List = Data()
End With
End Sub
Macro Example - This could be attached to a button
Sub LoadAllDropDowns()
' This loads uniques in range A1:A10 of the active sheet into
' the drop down named "Drop Down 1" on "Sheet1"
LoadUniquesInDropDown Range("A1:A10"), WorkSheets("Sheet1").DropDowns("Drop Down 1")
' Repeat the above method for each drop down you want to load
' Note: Drop Downs must be prefixed with the Worksheet they
' belong to. A Range without a prefix is assumed to be
' on the Active Sheet.
End Sub
Sincerely,
Leith Ross
Bookmarks