dcsimg
Results 1 to 5 of 5

Thread: Populate cells with Listbox selections (Excel 2003)

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    2

    Populate cells with Listbox selections (Excel 2003)

    Hi all...I cannot seem to find a solution to the most basic form of this question:

    I have a ListBox which contains about 30 options which can be selected - multiple selections possible. The ListBox is part of a form to book advertisements and the ListBox contains different newspaper titles.

    If a user selects titles A, B and C for example, is there a way to populate cells U1, U2, and U3 with these results? Obviously, if there are more selections made, then the list would grow.

    I'd then like a button to clear all options if a user wants to reset the selections (once the form is complete, it gets printed out).

    Hope I've explained clearly enough.

    Thanks in advance.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,729

    Re: Populate cells with Listbox selections (Excel 2003)

    you would need to loop through all the list box items and add the selected ones to the worksheet

    try like
    Code:
    For i = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(i) Then
            rw = rw + 1
            Sheets("sheet2").Cells(rw, 21) = ListBox1.List(i, 0)
        End If
    Next
    change sheet and listbox names to suit
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2018
    Posts
    2

    Re: Populate cells with Listbox selections (Excel 2003)

    Thanks. Used code below - do I need to link to a button? With this I get Run-time eror 424: Object required. Debug points to "For i = 0...." row

    Private Sub Button41_Click()
    'Add ListBox38 values to column U
    For i = 0 To ListBox38.ListCount - 1
    If ListBox38.Selected(i) Then
    rw = rw + 1
    Sheets("Input").Cells(rw, 21) = ListBox38.List(i, 0)
    End If
    Next
    End Sub

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,506

    Re: Populate cells with Listbox selections (Excel 2003)

    sounds like you may not have a list box called 'listbox38'

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,729

    Re: Populate cells with Listbox selections (Excel 2003)

    is the button on the same form as the listbox?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width