PDA

View Full Version : Understanding Multi Column Listbox



pcsparky
01-22-2009, 11:18 PM
I know that I want a 2 column Listbox to display a list of handlers and their dogs.

I have been trying to understand the concept of populating such a Listbox but after a few hours of research on the net I'm stumped.

I've managed to get this so far:

With ListBox1
.ColumnCount = 2
.ColumnHeads = False

.AddItem [handlerName]
.List(0, 1) = [dogName]


End With

The loop that I have populates the left column fine but the right column only shows the last dog's name in the data list (at the top of the listbox).

Obviously I'd like to get help on getting this to work but if anyone can explain this better than what I've read so far I'd be very grateful.

Jan Karel Pieterse
01-23-2009, 02:57 AM
Suppose your data is in range A1:B10 on worksheet "data" (col. A holds handler name, col B holds dog name):

Sub PopulateLB()
Dim oCell As Range
With ListBox1
.ColumnCount = 2
.ColumnHeads = False
For Each oCell In Worksheet("Data").Range("A1:A10")
.AddItem oCell.Value
.List(.ListCount - 1, 1) = oCell.Offset(, 1).Value
Next
End With
End Sub

pcsparky
01-23-2009, 11:06 AM
Thanks. I had my loop outside the With command. Got it working now.