+ Reply to Thread
Results 1 to 5 of 5

How to use selected items from Listbox

  1. #1

    How to use selected items from Listbox

    I use a listbox for making multiple selections, next I want to use this
    selection as input for another sub as an array. How do I do that?


  2. #2
    Tom Ogilvy
    Guest

    RE: How to use selected items from Listbox

    It is unclear whether you just want to be able to determine which items are
    selected or if you actually want to store that information in an array (or if
    you want the entire list in an array along with information on which is
    selected).
    to get the selected items

    With userform1.Listbox1
    for i = 0 to .listcount - 1
    if .selected(i) then
    ' build array?
    msgbox .List(i) & " is selected"
    end if
    Next
    End With

    --
    Regards,
    Tom Ogilvy


    "[email protected]" wrote:

    > I use a listbox for making multiple selections, next I want to use this
    > selection as input for another sub as an array. How do I do that?
    >
    >


  3. #3
    Fox_ghk
    Guest

    Re: How to use selected items from Listbox

    Tom,

    I want to build an array based on the selected items, and use this
    array in another sub.

    Regards
    Gerard


  4. #4
    Tom Ogilvy
    Guest

    Re: How to use selected items from Listbox

    Sub ABC()
    Dim i as Long, v as Variant

    With userform1.Listbox1
    redim v(0 to .listcount - 1)
    j = 0
    for i = 0 to .listcount - 1
    if .selected(i) then
    v(j) = .list(i)
    j = j + 1
    end if
    Next
    redim preserve v(0 to j-1)
    End With
    Mysub v

    end sub

    Sub Mysub(v as Variant)
    for i = lbound(v) to ubound(v)
    debug.print i, v(i)
    Next
    end Sub

    --
    Regards,
    Tom Ogilvy



    "Fox_ghk" wrote:

    > Tom,
    >
    > I want to build an array based on the selected items, and use this
    > array in another sub.
    >
    > Regards
    > Gerard
    >
    >


  5. #5
    Fox_ghk
    Guest

    Re: How to use selected items from Listbox

    Tom,

    Many Thanks
    I think I can do something nice with it.

    Gerard


+ 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