Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Populate Combo Box Drop Down with Collection Data
Hey guys,
i previously put a post up about optimising a search feature in a piece of VBA i was writting, but i have decided against this now as it would just take up too much time. my new idea of getting around this problem is to take all the values in a column, pick out 1 instance of each (Via a collection) and then out put that collection to a drop down menu/Combo Box. this is the code i have so far, i am just unsure about how to get the collection data into the combo box. Sub DropDown() Dim Cell As Range Dim Rng As Range Dim ListEntry As Collection Sheet1.ComboBoxEntry.Clear Application.ScreenUpdating = False Set Rng = Sheets("Data").Range("D:D") On Error Resume Next For Each Cell In Rng ListEntry.Add Cell.Value, CStr(Cell.Value) Next Cell For Each Item In ListEntry 'I didnt expect this line to work, just added it to illustrate what i am after. Sheets("Summary").ComboBoxEntry.AddItem Next Item Application.ScreenUpdating = True End Sub i have put this piece of code on the "ThisWorkbook" area of the VBA enviroment, i have had problems with combo boxes in other work books when i put code in the sheet the box was on. any help would be very welcome The Noob |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Populate Combo Box Drop Down with Collection Data
Nevermind, problem solved.
The Noob "Noob McKnownowt" wrote: Hey guys, i previously put a post up about optimising a search feature in a piece of VBA i was writting, but i have decided against this now as it would just take up too much time. my new idea of getting around this problem is to take all the values in a column, pick out 1 instance of each (Via a collection) and then out put that collection to a drop down menu/Combo Box. this is the code i have so far, i am just unsure about how to get the collection data into the combo box. Sub DropDown() Dim Cell As Range Dim Rng As Range Dim ListEntry As Collection Sheet1.ComboBoxEntry.Clear Application.ScreenUpdating = False Set Rng = Sheets("Data").Range("D:D") On Error Resume Next For Each Cell In Rng ListEntry.Add Cell.Value, CStr(Cell.Value) Next Cell For Each Item In ListEntry 'I didnt expect this line to work, just added it to illustrate what i am after. Sheets("Summary").ComboBoxEntry.AddItem Next Item Application.ScreenUpdating = True End Sub i have put this piece of code on the "ThisWorkbook" area of the VBA enviroment, i have had problems with combo boxes in other work books when i put code in the sheet the box was on. any help would be very welcome The Noob |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How can I populate a drop down list from Data Validation? | Excel Discussion (Misc queries) | |||
Populate combo box with external data | Excel Programming | |||
Populate Data w/ Multiple Drop-Downs | Excel Discussion (Misc queries) | |||
Populate a column of data with a formula using a drop down list | Excel Discussion (Misc queries) | |||
Populate one combo box based on the selection of another combo box | Excel Programming |