Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combox box question
Hi,
Is there a way to populate more than one combobox with the same information apart from just repeating the code? At the moment I'm using the additem function. Many thanks David |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combox box question
it's clumsy but your add item loop could include all your
combos for each item in mylist .additem item.value sheet1.combo1.additem item.value userform2.combo3.additem item.value next another way would be to set the combo's source from a named range In the following demo I have an ActiveX Combo on one sheet, and ActiveX Listbox on another sheet and a combobox on a userfom The code below is on a standard module...the procedure Initialise fetches data from a "database", pushes it into a column that gets range named, then assigns the name to the source of the three objects. on your active sheet, range name one cell as "MyList" to begin with. Option Explicit Public Sub inititialise() Dim col As New Collection Dim item Dim index As Long Dim rTarget As Range Set rTarget = Sheet2.Range("MyList") With rTarget .Clear .Resize(1, 1).Name = "MyList" End With Set rTarget = Sheet2.Range("MyList") Set col = GetFromDatabase For Each item In col rTarget.Offset(index, 0).Value = item index = index + 1 Next rTarget.Resize(index, 1).Name = "MyList" Sheet1.ComboBox1.ListFillRange = "MyList" Sheet2.ListBox1.ListFillRange = "MyList" UserForm1.ComboBox1.RowSource = "MyList" UserForm1.Show vbModeless End Sub Private Function GetFromDatabase() As Collection Dim c As New Collection With c .Add "Mike" .Add "Patrick" .Add "Ivan" .Add "Fola" .Add "Nit" End With Set GetFromDatabase = c Set c = Nothing End Function Hpe this demo gives you some ideas Patrick Molloy Microsoft Excel MVP -----Original Message----- Hi, Is there a way to populate more than one combobox with the same information apart from just repeating the code? At the moment I'm using the additem function. Many thanks David . |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Combox box question
Yes, set-up the information in a worksheet and use the ListFillRange
property (RowSource if a userform) to point at that range. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "David Goodall" wrote in message ... Hi, Is there a way to populate more than one combobox with the same information apart from just repeating the code? At the moment I'm using the additem function. Many thanks David |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Display data in a combox box | Excel Discussion (Misc queries) | |||
Assigning a value to a cell from a combox | Excel Discussion (Misc queries) | |||
Combox Locking | Excel Discussion (Misc queries) | |||
Combox/Print issue | Excel Programming | |||
continued combox frustration | Excel Programming |