+ Reply to Thread
Results 1 to 8 of 8

How do I get value of a multi-selection form listbox?

  1. #1
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    How do I get value of a multi-selection form listbox?

    I've never used the form listbox before. I've always used data validation list.

    How do I get the selections into my macro? I have my macro putting the listbox into an object, but I can't find a value.
    Please Login or Register  to view this content.
    Last edited by foxguy; 07-15-2010 at 12:49 AM.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How do I get value of a multi-selection form listbox?

    Hello foxguy,

    You have to loop through the entries and test if the Selected property is true.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: How do I get value of a multi-selection form listbox?

    Hi Leith;

    Yeah, I figured it out on my own. I was coming here to mark the thread solved and saw your message.

  4. #4
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: How do I get value of a multi-selection form listbox?

    Hi Leith;

    Can you explain this?
    In my macro I assign the listbox to an object. In the locals window I look at the object and the ListCount says 0 even though I have 3 items selected.
    And when I type ? .ListCount in the immediate window, I get 3.

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: How do I get value of a multi-selection form listbox?

    What was the code you used to assign it, and which line were you on? (Note: Listcount has nothing to do with how many items you have selected, it's the number of items in the list)
    Remember what the dormouse said
    Feed your head

  6. #6
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: How do I get value of a multi-selection form listbox?

    Quote Originally Posted by romperstomper View Post
    What was the code you used to assign it, and which line were you on? (Note: Listcount has nothing to do with how many items you have selected, it's the number of items in the list)
    Here is my entire sub.
    Please Login or Register  to view this content.
    It printed 3 in the immediate window.
    When it hit the Stop, I opened the Locals window and expanded "o". It said that Listcount was 0. There were three items in the List, and 2 of them were selected (strText correctly had 2 lines in it).

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: How do I get value of a multi-selection form listbox?

    Interesting - I've never noticed that before (It also has the ListIndex wrong). Even if you populate the listbox using AddItem, the Listcount still shows as 0. It would appear that it is actually only picking up the properties set at design time for some reason (presumably ListCount doesn't count since it could be assigned a dynamic range)

  8. #8
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: How do I get value of a multi-selection form listbox?

    And that explains why I had a hard time trying to extract the value. I kept looking at the listcount=0 and assuming it had nothing to do with what I was looking for.

    Live & learn.

+ 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