Consulting

Results 1 to 7 of 7

Thread: Solved: Listbox populated by Userform selections

  1. #1
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location

    Solved: Listbox populated by Userform selections

    Your assistance is greatly appreciated ,

    I have a userform containing three selection comboboxes and a command button to post selections to the userform listbox, a listbox to hold the posted selections and a command button to populate my worksheet with the list .

    I cannot work out the code to continually populate the listbox with the posted selections made, then pass the entire list to my worksheet! !


    Mike

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hi Mike,

    Would you be able to post a workbook with the userform you have so far, or if your workbook would have sensitive information then just the code you have so far?

    Without that, all we can really do is give you a guide.. but if you'd like that give me a couple minutes I can write up a quick example of one way you could do it

    Matt

  3. #3
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Ok, just a quick example of the methods you could use:[vba]Private Sub CmdBtnComboBoxStuffToListbox_Click()
    ListBox1.AddItem ComboBox1.Value
    ListBox1.AddItem ComboBox2.Value
    ListBox1.AddItem ComboBox3.Value
    End Sub
    Private Sub CmdBtnListboxToSheet_Click()
    Range("A1").Resize(ListBox1.ListCount, 1).Value = ListBox1.List
    Unload Me
    End Sub[/vba]

  4. #4
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location
    Appreciate your assistance on this matt.
    I'll try the piece of code and let you know how it goes.........
    Kindest Regards,
    Mike

    I love to Excel

  5. #5
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location

    Post

    Matt,

    I've attached an example workbook in order to avoid any info breach
    Kindest Regards,
    Mike

    I love to Excel

  6. #6
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Interesting that Aaron Blood is the author of your workbook

    What you're going to want to do is change the ColumnCount property of your listbox to 3 (since you have 3 comboboxes that you want added as one record). As an FYI, listbox lists have a base of 0, so columns 1,2,3 would be 0,1,2 to VBA (should help for future edits).

    To add the entries to the listbox, you'll need something like:[vba]Private Sub CommandButton1_Click()
    ListBox1.AddItem ComboBox1.Value
    ListBox1.List(ListBox1.ListCount - 1, 1) = ComboBox2.Value
    ListBox1.List(ListBox1.ListCount - 1, 2) = ComboBox3.Value
    End Sub[/vba]If it will help you realize what is going on, you can separate my line 1 into 2 parts. AddItem adds a new row to the listbox, so in reality what I'm doing is (this also works):[vba]Private Sub CommandButton1_Click()
    ListBox1.AddItem
    ListBox1.List(ListBox1.ListCount - 1, 0) = ComboBox1.Value
    ListBox1.List(ListBox1.ListCount - 1, 1) = ComboBox2.Value
    ListBox1.List(ListBox1.ListCount - 1, 2) = ComboBox3.Value
    End Sub[/vba]


    Next, you'll want to move the list to the worksheet (on the Front_End sheet, starting on the next available row in column D it seems):[vba]Private Sub CommandButton2_Click()
    Sheets("Front_End").Cells(Rows.Count, "D").End(xlUp).Offset(1, 0).Resize( _
    ListBox1.ListCount, ListBox1.ColumnCount).Value = ListBox1.List
    Unload Me
    End Sub[/vba]Let me know if you get stuck on any other part of this!
    Matt

  7. #7
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location

    SOLVED.......

    Matt,

    Thanks for the help so far....
    • Because I'm modifying one of Aaron's creations I thought it best I leave his reference.
    I've used the code and it works fine

    Thanks again, no doubt I'll be back
    Kindest Regards,
    Mike

    I love to Excel

Posting Permissions

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