-
Understanding Multi Column Listbox
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.
-
Suppose your data is in range A1:B10 on worksheet "data" (col. A holds handler name, col B holds dog name):
[vba]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
[/vba]
-
Thanks. I had my loop outside the With command. Got it working now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules