Returning multiple items from a listbox

Discussion in 'Microsoft Excel Misc' started by Kevlar, Sep 15, 2004.

  1. Kevlar

    Kevlar Guest

    I've done a lot of unsuccessful searching on this forum for this answer
    I want to be able to select multiple items from a list box and retur
    the results to a range.

    I've found this code;

    Private Sub CommandButton1_Click()

    For x = 0 To ListBox1.ListCount - 1

    If ListBox1.Selected(x) = True Then
    ActiveCell.Value = UserForm1.ListBox1.List(x)

    End If
    Next x

    End Sub

    But it returns all selections to a single cell. What I need it to do i
    return the first selection to A1, the second to A2, etc.

    By the way, this site is awesome and has never let me down, pleas
    don't fail me now! :

    --
    Message posted from http://www.ExcelForum.com
     
    Kevlar, Sep 15, 2004
    #1
    1. Advertisements

  2. How about:

    Private Sub CommandButton1_Click()
    dim X as long
    dim oRow as long

    orow = 1
    with worksheets("sheet1")
    For x = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(x) = True Then
    .cells(orow,"A").value = UserForm1.ListBox1.List(x)
    orow = orow + 1
    end if
    Next x
    end with
    End Sub

    "Kevlar <" wrote:
    >
    > I've done a lot of unsuccessful searching on this forum for this answer.
    > I want to be able to select multiple items from a list box and return
    > the results to a range.
    >
    > I've found this code;
    >
    > Private Sub CommandButton1_Click()
    >
    > For x = 0 To ListBox1.ListCount - 1
    >
    > If ListBox1.Selected(x) = True Then
    > ActiveCell.Value = UserForm1.ListBox1.List(x)
    >
    > End If
    > Next x
    >
    > End Sub
    >
    > But it returns all selections to a single cell. What I need it to do is
    > return the first selection to A1, the second to A2, etc.
    >
    > By the way, this site is awesome and has never let me down, please
    > don't fail me now! :)
    >
    > ---
    > Message posted from http://www.ExcelForum.com/


    --

    Dave Peterson
     
    Dave Peterson, Sep 16, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    pivot table returning a "value in the data items"

    Guest, Sep 30, 2005, in forum: Microsoft Excel Misc
    Replies:
    1
    Views:
    154
    Debra Dalgleish
    Oct 4, 2005
  2. Guest

    order form with multiple items and sizes for items

    Guest, Jan 17, 2006, in forum: Microsoft Excel Misc
    Replies:
    1
    Views:
    257
    Debra Dalgleish
    Jan 17, 2006
  3. MP
    Replies:
    0
    Views:
    229
  4. kookie
    Replies:
    4
    Views:
    293
    Gord Dibben
    Jan 19, 2009
  5. ExcelWizardImNot

    counting identical items in a column and returning the occurrences

    ExcelWizardImNot, Mar 27, 2010, in forum: Microsoft Excel Misc
    Replies:
    3
    Views:
    179
    מיכ×ל (מיקי) ×בידן
    Mar 27, 2010
Loading...

Share This Page