+ Reply to Thread
Results 1 to 5 of 5

Listbox (MultiSelect)

Hybrid View

  1. #1
    Forum Contributor CobraLAD's Avatar
    Join Date
    07-23-2007
    Location
    Boksburg, South Africa
    MS-Off Ver
    Office 2019
    Posts
    346

    Listbox (MultiSelect)

    I have about 200 names in column A which I list in a listbox on a userfrom, which is set to multiselect

    I want to be able to select certain names, and copy them to column G. I can do it with single select.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Private Sub CommandButton1_Click()
    Dim i As Long, n As Long, a()
    With ListBox1
        If .ListIndex = -1 Then Exit Sub
        ReDim a(1 To .ListCount + 1, 1 To 1)
        For i = 0 To .ListCount - 1
            If .Selected(i) Then
                n = n + 1 : a(n,1) = .List(.ListIndex)
            Next
        Next
    End With
    Sheets("YourSheetNameHere").Range("g" & Rows.Count).End(xlUp)(2).Resize(n).Value = a
    End Sub

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Multi selected items to worksheet

    Here's a code that will place all the selected items from the listbox and place them in the first empty cell in column G
    Private Sub CommandButton2_Click()
    Dim lItem As Long
        For lItem = 0 To ListBox1.ListCount - 1
            If ListBox1.Selected(lItem) = True Then
                Sheet2.Range("G65536").End(xlUp)(2, 1) = ListBox1.List(lItem)
                ListBox1.Selected(lItem) = False
            End If
        Next
    End Sub

  4. #4
    Forum Contributor CobraLAD's Avatar
    Join Date
    07-23-2007
    Location
    Boksburg, South Africa
    MS-Off Ver
    Office 2019
    Posts
    346
    Hi

    Thanks Dave, I first saw nothing in column G, but then I noticed, sheet2

    thanks it works
    Last edited by CobraLAD; 03-13-2008 at 11:56 PM.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Should be working if you change the sheet name to appropreate.

+ 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