+ Reply to Thread
Results 1 to 12 of 12

Array returning only first item

  1. #1
    Registered User
    Join Date
    11-24-2011
    Location
    Chattanooga, TN
    MS-Off Ver
    Microsoft 365 MSO (Version 2303 Build 16.0.16227.20202) 64-bit
    Posts
    11

    Array returning only first item

    I have a worksheet table with contacts ("Leads"). I also have a userform to interact with the list ("FormInputs"). On the userform is a Listbox ("ContactList").

    When I filter the list for say, "medical" contacts or "client" contacts, the listbox is re-populated with only the filtered results/visible contact names & respective row numbers.

    I'm a fairly proficient leach of other people's code but I have copied, pasted, cut and added so much I no longer know what I'm doing. On top of that, arrays are something I can never seem to get my head around. Is there something simple someone can point out that I'm doing wrong? And please don't say the thing I'm doing wrong is "messing with code". My feelings will be hurt and I'll never be able to lie to others about how great I am . . .

    Thank you all!

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Array returning only first item

    Hello.
    It's true: It will never work for you that way and you will always get the first visible row!

    Alternatively, try the following:

    Please Login or Register  to view this content.
    Last edited by beyond Excel; 05-06-2023 at 01:06 PM.
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  3. #3
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Array returning only first item

    just a guess
    When you use a filter, your data isn't an contigious block, so your array isn't complet. Also if no data is left after filtering, you get another error.
    So, a little workaround, is copying and pasting the filtered data (in case of ...) to an auxiliary range of your sheet as 1 contigious block, then read it into your array and ...

    Please Login or Register  to view this content.
    Edit : same idea as @Beyond Excel
    Last edited by bsalv; 05-06-2023 at 01:06 PM.
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Array returning only first item

    Hi. It may not be especially relevant for this query, but...


    Is your forum profile showing the Excel PRODUCT that you need this request to work with?

    The best solutions often rely on knowing WHICH Office PRODUCT (Excel, NOT Windows) that you have. Please check that your forum profile is up-to-date. If you aren't sure, in Excel go to File/Account and report what it says below the MS logo at the top of that page. If your version is for Mac, please also state this.

    The three most recent Excel PRODUCTS are Excel 2019, Excel 2021 and MS365 - if you are using MS365, please give this name along with the Version number in your profile (e.g. MS365 (PC) Version 2211). The version number is in the About Excel section further down the Account page.

    Cheers,

    Glenn.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,484

    Re: Array returning only first item

    No need to filter and copy to alternate sheet or cell...
    Supply a sample sheet and someone will offer alternate solutions...
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  6. #6
    Registered User
    Join Date
    11-24-2011
    Location
    Chattanooga, TN
    MS-Off Ver
    Microsoft 365 MSO (Version 2303 Build 16.0.16227.20202) 64-bit
    Posts
    11

    Re: Array returning only first item

    Thank you for the info Glenn. My profile was a 'little' outdated. Apparently I had not updated it since Excel 2003. I have updated it now.

  7. #7
    Registered User
    Join Date
    11-24-2011
    Location
    Chattanooga, TN
    MS-Off Ver
    Microsoft 365 MSO (Version 2303 Build 16.0.16227.20202) 64-bit
    Posts
    11

    Re: Array returning only first item

    Thank you, beyond Excel. I am playing with your solution now, testing on different filters, etc. Thank you for taking your valuable time to help me!
    Sincerely,
    David

  8. #8
    Registered User
    Join Date
    11-24-2011
    Location
    Chattanooga, TN
    MS-Off Ver
    Microsoft 365 MSO (Version 2303 Build 16.0.16227.20202) 64-bit
    Posts
    11

    Re: Array returning only first item

    Even though beyond Excel beat you to it, thank you bsalv for taking the time to help me. It lends credence to the solution that both of you had the same idea.

    Sincerely,
    David

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,484

    Re: Array returning only first item

    It lends credence to the solution that both of you had the same idea.
    See post 5 for alternate idea...

  10. #10
    Registered User
    Join Date
    11-24-2011
    Location
    Chattanooga, TN
    MS-Off Ver
    Microsoft 365 MSO (Version 2303 Build 16.0.16227.20202) 64-bit
    Posts
    11

    Re: Array returning only first item

    That is a very kind offer, sintek. At this point though, I think beyond Excel & bsalv have a solid solution. If someone starts giving me alternatives now, my head would explode.

    I do appreciate the offer though!

    Sincerely,
    David

  11. #11
    Registered User
    Join Date
    11-24-2011
    Location
    Chattanooga, TN
    MS-Off Ver
    Microsoft 365 MSO (Version 2303 Build 16.0.16227.20202) 64-bit
    Posts
    11

    Re: Array returning only first item

    I have been playing with the solutions given by beyond Excel & bsalv.

    Initially, I thought the two were the same, but after actually reading through them, I see that they are not. I tried both solutions and have to say, bsalv's solution was easier for my brain to understand and it worked straight "out of the box". I got a little confused with beyond Excel's solution at the point of adding my filter because I have several filters which are dependent on other selections.

    For me and my situation, I am going with bsalv's solution as the solution.

    Regardless, both were very kind to help me and I genuinely appreciate it.

    Sincerely,
    David

  12. #12
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,484

    Re: Array returning only first item

    Not to worry...All good...
    Happy Coding...
    Last edited by Sintek; 05-07-2023 at 11:17 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 12-11-2021, 06:45 AM
  2. [SOLVED] A dictionary of array items - unable to update an item array value
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2021, 08:43 AM
  3. [SOLVED] Loop is not triggered when using an array if first item in array is not found
    By Ianmacros in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2019, 01:35 PM
  4. [SOLVED] Filter Array 1 with Array 2 as criteria, returning filtered data to source sheet
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-31-2019, 01:08 PM
  5. [SOLVED] Returning max number of a certain item
    By campelliann in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-12-2015, 04:54 AM
  6. [SOLVED] If dictionary key exists add new item to existing item array
    By strud in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-25-2014, 01:54 PM
  7. Replies: 4
    Last Post: 12-23-2013, 08:43 AM

Tags for this Thread

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