+ Reply to Thread
Results 1 to 11 of 11

Alternative for lookup_concat required

  1. #1
    Valued Forum Contributor
    Join Date
    07-27-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    826

    Alternative for lookup_concat required

    Hello guys,

    Here I am looking for help again

    Please see my attached example file. I need to input a unique ID number in a cell (F3 in my example), and have a set of values which relate to (possibly multiple instances) of the unique ID returned - in my example, H3 should return all entries from column C where the entries in column A match what has been entered in F3. I can get it to return from one row at a time no problem, using INDEX/MATCH, but I need to show all entries in a single cell.

    I have tried the wonderful lookup_concat function, which requires the following:


    Please Login or Register  to view this content.

    to be inserted as a VBA module; however I find that after eg using the data filter, or saving, my workbook takes 30/40 seconds to finish with all "processes", as Excel describes them at the bottom of the page. I'm using a 2.5GH quad-core pc with 4GB ram, and have also tried this on an i3 machine at work, with the same problem, so I'm hoping that someone can help me out here with an alternative.

    Many thanks,

    Brendan.
    Attached Files Attached Files
    Last edited by BB1972; 09-08-2012 at 03:05 PM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,620

    Re: Alternative for lookup_concat required

    Adding code tags around code makes it easier to read and copy

  3. #3
    Valued Forum Contributor
    Join Date
    07-27-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    826

    Re: Alternative for lookup_concat required

    Quote Originally Posted by Pepe Le Mokko View Post
    Adding code tags around code makes it easier to read and copy
    That's done now.

  4. #4
    Valued Forum Contributor
    Join Date
    07-27-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    826

    Re: Alternative for lookup_concat required

    Come on, guys - I'm sure SOMEBODY out there can help me with this! Or can maybe explain what's causing the slow-down?

    Thanks,

    Brendan.

  5. #5
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: Alternative for lookup_concat required

    How many rows are we talking about?
    VBA in general is many times slower than the built in formulas of Excel.
    There are (most likely) multiple ways to do it with VBA and even though your code is clean, finding the next value with a loop and an IF is probably one of the slower ways to do it.

    I played around with the idea of using a using an array formula with CONCATENATE, which turned out to be a dead end since CONCATENATE does not work with array formulas. Just as well now that I think about it, large array formulas can be pretty slow.

    Using Find All (as in Ctrl + F) seemed like a slick solution, just get the range with the values you want and loop through it with OFFSET. I think FIND is pretty darn fast. While FIND is readily available in VBA, FINDALL is not and it's a hassle to emulate as is shown here: http://www.cpearson.com/excel/FindAll.aspx

    In the end I improved your code using MATCH to find the values with as I reckon it is many times faster than your IF loop. Quite bulky for a UDF but it works. Now it's up to you to do some speed comparisons.

    What would be cool is if any of the real smart guys out there could solve it with formulas only.

  6. #6
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: Alternative for lookup_concat required

    ...and some code and attachment.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    07-27-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    826

    Re: Alternative for lookup_concat required

    Hey Jacc,

    Thanks for the reply. We are talking about approx 1200 rows, by 75 columns.

    When you say you used MATCH, do you mean you substituted MATCH for IF in the UDF? I'll give that a shot now and see if it's faster...

    And while it would be awesome if the real smart guys came up with an answer, it'll be just as awesome if we can figure it out ourselves


    EDIT: I see your attachment and code now - thanks very much. I will report back!
    Brendan.


    __________________________________________________________________________________________________
    Things to consider:

    1) You can thank any poster by clicking the * at the left of a helpful post.
    2) You can help to keep the forum tidy by marking your thread as "Solved", if it has been answered to your satisfaction.
    3) Help us to help you, by uploading a sample workbook, showing the type of data you're dealing with, and clearly indicating what the results should be.

  8. #8
    Valued Forum Contributor
    Join Date
    07-27-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    826

    Re: Alternative for lookup_concat required

    Jacc,

    That is fantastic! There is ZERO discernible slow-down. Thank you very much for your help. Looks like you're one of the really smart guys after all

  9. #9
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: Alternative for lookup_concat required

    Thanks! Glad I could help!
    Smart guy? Well for some reason I never get along well with UDF's and this one was a prime example of that, it was tough.

    That being said, I just discovered I left out the icing on the cake!
    Change this:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.
    By adding "As String" you don't have an annoying zero to deal with if the name is not in the list. Besides, the function data type should be declared regardless.
    I found out just now when I realized I never tested the code for zero findings.

  10. #10
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: Alternative for lookup_concat required

    Well this is not the post I wanted to post. Despite the positive reception the above function does not work. Well it seem to work in a sorted list but not in general, which is what I aimed for obviously. This little toxic piece of code is the culprit:
    Please Login or Register  to view this content.
    .
    In a range with scattered cells it will not give the next cell in the range, just the next cell on the sheet. Hence it seems to work in a sorted list.
    The correct way of doing it is ofcourse to use the solid For Each loop.
    Please Login or Register  to view this content.
    I would really appreciate if someone could confirm that I'm on the right track again. I assume it worked so far for you Brendan, otherwise you would have posted, right?
    I discovered this as I was recycling this code for another post. I've recycled it before so I have to track down those posts as well and correct them.
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  11. #11
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: Alternative for lookup_concat required

    Much better code in this version. I'll just store it here so it won't get lost.
    Attached Files Attached Files

+ 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