+ Reply to Thread
Results 1 to 5 of 5

Need help with Listboxes!

  1. #1
    Registered User
    Join Date
    01-23-2006
    Posts
    5

    Question Need help with Listboxes!

    Alright, so here is my situation. I've tried to get this to work for a while now...and just can't seem to figure it out.

    Let's say you have columns A, B, C with data in them. Column D is a boolean value...true/false, 0/1, whatever.

    How would I populate a multi-column listbox with the data from A, B, and C depending on whether D is 0 or 1. So if it's 0, I want that row in the listbox, but if it's 1, I don't want it in the listbox. Of course I'd like this to work on all rows in the sheet.

    Could someone help me with the code for that?

    Thank you very much!

  2. #2
    Tom Ogilvy
    Guest

    Re: Need help with Listboxes!

    Private Sub UserForm_Initialize()
    Dim rng As Range
    ListBox1.ColumnCount = 4
    Set rng = Range(Cells(2, 1), Cells(2, 1).End(xlDown))
    For Each cell In rng
    If cell.Offset(0, 3) = 0 Then
    ListBox1.AddItem cell.Value
    ListBox1.List(ListBox1.ListCount - 1, 1) = cell.Offset(0, 1).Value
    ListBox1.List(ListBox1.ListCount - 1, 2) = cell.Offset(0, 2).Value
    ListBox1.List(ListBox1.ListCount - 1, 3) = cell.Offset(0, 3).Value
    End If
    Next

    End Sub


    worked for me.

    --
    Regards,
    Tom Ogilvy



    "Angelus" <Angelus.223qiy_1138043703.1187@excelforum-nospam.com> wrote in
    message news:Angelus.223qiy_1138043703.1187@excelforum-nospam.com...
    >
    > Alright, so here is my situation. I've tried to get this to work for a
    > while now...and just can't seem to figure it out.
    >
    > Let's say you have columns A, B, C with data in them. Column D is a
    > boolean value...true/false, 0/1, whatever.
    >
    > How would I populate a multi-column listbox with the data from A, B,
    > and C depending on whether D is 0 or 1. So if it's 0, I want that row
    > in the listbox, but if it's 1, I don't want it in the listbox. Of
    > course I'd like this to work on all rows in the sheet.
    >
    > Could someone help me with the code for that?
    >
    > Thank you very much!
    >
    >
    > --
    > Angelus
    > ------------------------------------------------------------------------
    > Angelus's Profile:

    http://www.excelforum.com/member.php...o&userid=30721
    > View this thread: http://www.excelforum.com/showthread...hreadid=504144
    >




  3. #3
    Registered User
    Join Date
    01-23-2006
    Posts
    5
    Wow. Thanks a lot!

    Quote Originally Posted by Tom Ogilvy
    Private Sub UserForm_Initialize()
    Dim rng As Range
    ListBox1.ColumnCount = 4
    Set rng = Range(Cells(2, 1), Cells(2, 1).End(xlDown))
    For Each cell In rng
    If cell.Offset(0, 3) = 0 Then
    ListBox1.AddItem cell.Value
    ListBox1.List(ListBox1.ListCount - 1, 1) = cell.Offset(0, 1).Value
    ListBox1.List(ListBox1.ListCount - 1, 2) = cell.Offset(0, 2).Value
    ListBox1.List(ListBox1.ListCount - 1, 3) = cell.Offset(0, 3).Value
    End If
    Next

    End Sub


    worked for me.

    --
    Regards,
    Tom Ogilvy



    "Angelus" <Angelus.223qiy_1138043703.1187@excelforum-nospam.com> wrote in
    message news:Angelus.223qiy_1138043703.1187@excelforum-nospam.com...
    >
    > Alright, so here is my situation. I've tried to get this to work for a
    > while now...and just can't seem to figure it out.
    >
    > Let's say you have columns A, B, C with data in them. Column D is a
    > boolean value...true/false, 0/1, whatever.
    >
    > How would I populate a multi-column listbox with the data from A, B,
    > and C depending on whether D is 0 or 1. So if it's 0, I want that row
    > in the listbox, but if it's 1, I don't want it in the listbox. Of
    > course I'd like this to work on all rows in the sheet.
    >
    > Could someone help me with the code for that?
    >
    > Thank you very much!
    >
    >
    > --
    > Angelus
    > ------------------------------------------------------------------------
    > Angelus's Profile:

    http://www.excelforum.com/member.php...o&userid=30721
    > View this thread: http://www.excelforum.com/showthread...hreadid=504144
    >

  4. #4
    Registered User
    Join Date
    01-23-2006
    Posts
    5
    Okay, I need a little more help here.

    Once an entry in the listbox is selected and a command button is pushed, how do I get the value of the second column?

    It would be something like:

    newVariable = ListBox1.List(X, 1)

    What do I put where the X is to specify the entry that has been selected? Thanks.

  5. #5
    Registered User
    Join Date
    01-23-2006
    Posts
    5
    Nevermind, I figured it out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1