Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi Column Combobox 1

Status
Not open for further replies.

ninash

Technical User
Jul 6, 2001
163
GB
Hi All,

I have a spreadsheet where rows of data have been saved.
I would like to used this data in a combo box but am stuck how to make a combo box list more then 1 column of data and how to load the data into said combo box.

The code I use to make a single column combo box is listed below

Dim Row As Integer
Dim Data As Object
Set Data = Sheets("Logo").Cells

Row = 1
While Not IsEmpty(Data(Row, 1))
ComboBox1.AddItem (Data(Row, 1))
Row = Row + 1
Wend

Can Anyone tell me how to make this code handle more then one column of data
Thanks

Tony
 
This snippet from VBA's help demonstrates how to go about it pretty well.

Private Sub UserForm_Initialize()
Dim i As Single
'The 1st list box contains 3 data columns
ListBox1.ColumnCount = 3
'The 2nd box contains 6 data columns
ListBox2.ColumnCount = 6

'Load integer values into first column of MyArray
For i = 0 To 5
MyArray(i, 0) = i
Next i

'Load columns 2 and three of MyArray
MyArray(0, 1) = "Zero"
MyArray(1, 1) = "One"
MyArray(2, 1) = "Two"
MyArray(3, 1) = "Three"
MyArray(4, 1) = "Four"
MyArray(5, 1) = "Five"

MyArray(0, 2) = "Zero"
MyArray(1, 2) = "Un ou Une"
MyArray(2, 2) = "Deux"
MyArray(3, 2) = "Trois"
MyArray(4, 2) = "Quatre"
MyArray(5, 2) = "Cinq"

'Load data into ListBox1 and ListBox2
ListBox1.List() = MyArray
ListBox2.Column() = MyArray
End Sub

Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top