PDA

View Full Version : add multiple array to combobx



fadib
01-15-2009, 05:26 PM
Hi guys,
how can I add an array of item (4 , 5, 6 ) to a combobox without deleting the existing ones (1 ,2, 3 )?
I also want to do that when I open my excel sheet.
cboValLookFor.List = Array("1", "2", "3")
cboValLookFor.List = Array("4", "5", "6")

Bob Phillips
01-15-2009, 05:33 PM
You can't. You either join the arrays, or load the second item by item



Dim i As Long
Dim ary As Variant

With cboValLookFor

.List = Array("1", "2", "3")
ary = Array("4", "5", "6")
For i = LBound(ary) To UBound(ary)

.AddItem ary(i)
Next i
End With

fadib
01-15-2009, 05:48 PM
Awesom!
how can I do that as soon as I open my excel sheet.
I also want to know how to arrange the numbers from low to high.

Bob Phillips
01-16-2009, 02:45 AM
It all depends on what you mean by open your Excel sheet, what sort of combobox it is, and where the data is coming from.

fadib
01-16-2009, 10:24 AM
You are right XLD (Dah!!) I don't need to populate the combobox when excel opens, cause I am doing that as soon as I click on the arrow of the combobox.
what about sorting the data, after I use the previous code?

Bob Phillips
01-16-2009, 10:39 AM
As I said, iI all depends on ... what sort of combobox it is, and where the data is coming from.

fadib
01-16-2009, 01:51 PM
I am entering the data manualy in the code. I am gonna create multiple array and I will use the code to add them to the combobox.
as to what sort of combobox it is, it is not a list box. Maybe I am not understanding what you mean by sort of combobox. can you give an example?

fadib
01-16-2009, 02:08 PM
It is a dropdown combobox

fadib
01-16-2009, 02:28 PM
I have attached a sample of what I am trying to do.
In sheet1 I have the data, and in sheet 2 I have the combobox.
I am trying to populate the combobox in sheet2 with the numbers found in sheet1.