+ Reply to Thread
Results 1 to 10 of 10

Add Listbox Values to an Array

  1. #1
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Oxford
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    120

    Thumbs up Add Listbox Values to an Array

    Hey all,

    I have two listboxes the user selects the value from one listbox and puts it to the next listbox. i then want to run a code to look through the second listbox and add each item in the listbox to an array.

    the code i have works if the user clicks on the first item in the listbox, but it doesnt work if they dont. i want it to work if the user hasnt clicked on the first item, i just want it to look through and get all values.

    Please Login or Register  to view this content.
    I though that the ListBox2.ListIndex = COUNT would select an item and then would get the value from it but it doesnt seam to work.

    Thanks
    Last edited by t0m46; 08-17-2010 at 07:25 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Add Listbox Values to an Array

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Oxford
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    120

    Re: Add Listbox Values to an Array

    Hey Thanks,

    Is there now a way to Msgbox each Item from the Listbox?

    I have Tried

    Please Login or Register  to view this content.
    and Msg
    Please Login or Register  to view this content.
    but it doesnt display anything

    Thansk

  4. #4
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Oxford
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    120

    Re: Add Listbox Values to an Array

    Hey,

    Not to Worry, i dont to Msgbox it now.

    Thanks That was anoyingly simple to get the items into an array.

  5. #5
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Oxford
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    120

    Exclamation Re: Add Listbox Values to an Array

    Hey,

    The Array isnt working with the list box with what i want to do.

    i want to get the values from the listbox, assaign to an array for each value in the listbox then filter them.

    Please Login or Register  to view this content.
    It breaks on the Filter part and comes up with Error Runtime Error 13, Type MisMatch

    I added a Watch and it looks like the values arent getting assigned to the array so it cant filter by anything.

    Thanks

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Add Listbox Values to an Array

    NARY is an array, so you don't use Array(NARY), you just use NARY. I assume you are using 2007 not 2003 since 2003 doesn't accept arrays as filter criteria.

  7. #7
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Oxford
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    120

    Re: Add Listbox Values to an Array

    Have Tried that and it still uses the same error.

    I am using 2007 and i have another filter that works with an array

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Add Listbox Values to an Array

    Ah, I guess you are using AddItem to populate the listbox? In that case use:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-27-2009
    Location
    Oxford
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    120

    Re: Add Listbox Values to an Array

    Hey,

    Yer sorry I should of said I was using .additem.

    That works now anyway.

    Thanks for all your help

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Add Listbox Values to an Array

    To be honest, I should have realised that based on your initial description!

+ 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