+ Reply to Thread
Results 1 to 6 of 6

Getting values from list box

  1. #1
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379

    Getting values from list box

    Good afternoon all, I have been having fun with listboxes all day and have one last(!) problem.

    I need to get all of the values from a listbox and place them in variables, the trouble is I do not know how many items there will be in the list box, no more than 20 probably. Can you help? Thanks in advance! Rep for all who help!
    Last edited by ChrisMattock; 12-09-2008 at 02:49 PM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good evening ChrisMattock

    Using the ListCount property should do the trick :
    Please Login or Register  to view this content.
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    Good evening Dominicb!

    Would you be so kind as to elaborate on that, I understand that supplies me with the number of values, but then how do I assign each value to a variable? If I even need to that is.

    In terms of output I am looking for a list down however many rows are necessary in an excel worksheet.

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi ChrisMattock

    Quote Originally Posted by ChrisMattock View Post
    Would you be so kind as to elaborate on that, I understand that supplies me with the number of values, but then how do I assign each value to a variable? If I even need to that is.
    The code below will dump the contents of ListXox1 into an array (a). The second block of code you don't need - it's just proving that all the items are there and shows you how to access them :

    Please Login or Register  to view this content.
    HTH

    DominicB

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    One has to be careful to be sure that you know if you are working with a 0 based array. Of course the listbox is 0 based. It is usually a matter of +/- 1 which can be done in the loop counter or the list index and index for the array.

    Here is my example. Make a() Public if you need it for later in the code.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    Hey guys, thanks for both of your help very much appreciated! SOLVED! +rep to you both.

+ 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