+ Reply to Thread
Results 1 to 9 of 9

Retrieve match from array items optimize time

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Retrieve match from array items optimize time

    Hello everyone
    I have this UDF (Narayan's from chandoo)
    Please Login or Register  to view this content.
    I intend to use that udf in a list of 200,000 rows ... How can I optimize that to make it faster?

    Thanks a lot for advanced help
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Retrieve match from array items optimize time

    Weirdly-built function. What are you trying to return? Currently it returns only the furthest-in first match of any of the items, so if there's multiple instances of the same code it may not return what you expect. Is this correct?
    It also returns an 'illegal' Excel error code 0, meaning the error return triggers another error which then defaults to an error of #VALUE (actually code 2015, or xlErrValue). The error #N/A (code 2042 or xlErrNA) is more applicable to the string not being found, like when VLOOKUP cannot find a match.
    Design everything to be as simple as possible, but no simpler.

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Retrieve match from array items optimize time

    Thanks a lot for reply
    There's no problem. If not match found I could put empty string instead of CVErr(0)
    The main problem is how to apply such idea on large amounts of data..

    As for your question .. yes I would like to return only the furthest-in first match of any of the items

  4. #4
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Retrieve match from array items optimize time

    Running the UDF on 200,000 cells only took 2.2 secs for me. I was able to shave it down to 2.0 secs by declaring your array explicitly.

    Please Login or Register  to view this content.
    Code for testing with calculation method set to manual and autofilling formula each time (so that it must be calculated):
    Please Login or Register  to view this content.


    If you do it purely in VBA you can get it down to 1.2 secs. Your decision if it's worth it *shrugs*
    Please Login or Register  to view this content.

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Retrieve match from array items optimize time

    Hi,

    Why use a UDF at all? I suspect a formula would be faster. Perhaps
    =IFERROR(MID(A1,AGGREGATE(14,6,FIND({"UY","OP","ST"},A1),1),2),"")
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Retrieve match from array items optimize time

    That is really awesome. Thank you very very much for this great solution
    Best Regards

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Retrieve match from array items optimize time

    Quote Originally Posted by xlnitwit View Post
    Hi,

    Why use a UDF at all? I suspect a formula would be faster. Perhaps
    =IFERROR(MID(A1,AGGREGATE(14,6,FIND({"UY","OP","ST"},A1),1),2),"")
    That works great too but it may grab the substring of the whole string
    Example : "HelloUY Good" >> It return "UY" .. It would be preceded with space and when trying " UY " it returns "U" only

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Retrieve match from array items optimize time

    It is OK I have changed 2 at the end of the formula to 3 and it worked. Thanks a lot for great help

  9. #9
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Retrieve match from array items optimize time

    A modification to nitwit's clever formula for your purposes:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Can confirm it returns the same result as UDF and VBA for these test strings:-

    TARGET UDF FORMULA VBA
    this string contains nothing #N/A #N/A #N/A
    this string contains ST and UY UY UY UY
    this string contains ST and UY and ST UY UY UY
    this string contains ST and UY and ST and OP OP OP OP
    this string contains ST and UY and ST and OP and ST OP OP OP


    If that takes care of your original question, please select Thread Tools from the menu link above to mark this thread as SOLVED.
    To say thanks to the user(s) who contributed towards the solution, you can use the "Add Reputation" button on their helpful post(s).
    Thanks!

+ 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: 03-12-2017, 03:20 PM
  2. Need to retrieve multiple row items given two criteria (Index, Match, Row)
    By tonyridino in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-13-2015, 04:02 PM
  3. Using the Match Function when items are not displayed in a perfect array?
    By larryg003 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-15-2015, 12:25 PM
  4. [SOLVED] Retrieve Data if multiple array condition is match
    By fiyas in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-12-2015, 03:32 PM
  5. Retrieve MAX value from array using INDEX and MATCH
    By paul724 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-02-2014, 10:07 AM
  6. [SOLVED] retrieve child items from visible pivot items.
    By MarMo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2013, 10:24 AM
  7. [SOLVED] Using Index and Match to search an array that has multiple items in each cell
    By tdlewis in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-20-2012, 08:45 PM

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