Consulting

Results 1 to 3 of 3

Thread: Understanding Multi Column Listbox

  1. #1
    VBAX Regular
    Joined
    Jan 2009
    Posts
    57
    Location

    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.

  2. #2
    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]
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Regular
    Joined
    Jan 2009
    Posts
    57
    Location
    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
  •