Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Spreadsheets (https://www.askmehelpdesk.com/forumdisplay.php?f=395)
-   -   Using VBA to extract ListBox items (https://www.askmehelpdesk.com/showthread.php?t=774142)

  • Nov 6, 2013, 10:12 AM
    jakester
    Using VBA to extract ListBox items
    I'm trying to create a module that will take selections from an activeX Listbox on a Sheet called Setup and transfer them to another sheet called Lists. On the Lists sheet, I want to store the selected items in cell L2 and down. So for example, if there were 4 items selected from the Listbox, cells L2:L5 would be populated with those values.

    Can anyone help me with this code?
  • Nov 6, 2013, 12:22 PM
    JBeaucaire
    So I don't have to create a pseudo workbook to test it, can you post your workbook as it is currently with any helpful notes within?

    This will be a loop through the ListBox.Items to determine each one that is selected and place them on the other sheet.

    Also, what if L2:L5 has data already? Should some cells be cleared first? How many cells?
  • Nov 6, 2013, 02:41 PM
    jakester
    Thanks, Jerry. I was able to find some code and I got it to work, finally.
  • Nov 6, 2013, 05:19 PM
    JBeaucaire
    Care to share? Others who search on their own may find this thread and your code snippet may help them.
  • Nov 7, 2013, 07:31 AM
    jakester
    Sure, here's my code:

    Quote:

    Sub SetupSelection()

    Dim UserSels() As Variant
    Dim SelCnt As Long
    Dim i As Long

    SelCnt = 0
    With Worksheets("Setup").ListBox1
    For i = 0 To .ListCount - 1
    If .Selected(i) Then
    SelCnt = SelCnt + 1
    ReDim Preserve UserSels(1 To SelCnt)
    UserSels(SelCnt) = .List(i)
    End If
    Next i
    End With

    If SelCnt > 0 Then
    Worksheets("Lists").Range("L2").Resize(UBound(User Sels)).Value = Application.Transpose(UserSels)
    Else
    MsgBox "No selections were made", vbInformation
    End If



    End Sub
    But I did encounter another issue that maybe you can help with. Inside of the ListBox, I cannot scroll up and down within the list using my mouse scroll. I have to manually click on the scroll bar to move up and down.

    Any solution?
  • Nov 7, 2013, 04:59 PM
    JBeaucaire
    Read through this thread, it offers a hefty solution to this simple problem with no simple answer:

    ListBox Mouse Scroll

  • All times are GMT -7. The time now is 01:25 PM.