+ Reply to Thread
Results 1 to 7 of 7

Fast Index/Match Alternative in VBA

  1. #1
    Registered User
    Join Date
    04-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Fast Index/Match Alternative in VBA

    Hey guys,

    I am just beginning to learn VBA. I knew a lot about Excel functions before making the leap to VBA so much of my excel knowledge is rooted in the functions. I am trying to create a code that needs to perform an =index(match()) kind of function. Basically I have an array that I place in the spreadsheet and then need to place their corresponding info next to them.

    The only way I have been able to think of so far is to use the application.index and application.match inside a for loop to get it done. However, I have to select the array in the formula in each loop and I am going through large amounts of data. It takes 5+ minutes to run just that part of my code. Does anyone know any faster/more efficient way to run this kind of code? I am open to any suggestions and can give a better explanation of how I am doing it now if needed.

    Thanks in advance
    If you found this helpful, click the star

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Fast Index/Match Alternative in VBA

    Instead of worksheetfunction.match you could use find method instead of index simply use addressing . But the gain will will probably not satisfy you.

    If we were about medium size datasets - I'd go into operations not directly on worksheet ranges, but on arrays of data
    like:
    Please Login or Register  to view this content.
    stop code here and look in the locals window what is in myarr.

    But as we are talking about realy large datasets, probably database approach would let you increase code speed from minutes to seconds.
    Keywors for search DAO ADO ADODB . And dont worry it can all (also datasource) be in excel. May be http://support.microsoft.com/kb/257819 or is a good starting point or may be http://www.vbadventure.com/2012/11/u...el-vba-part-1/
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    04-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Fast Index/Match Alternative in VBA

    Thanks for the reply I will look into those.

  4. #4
    Registered User
    Join Date
    04-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Fast Index/Match Alternative in VBA

    I am wondering if I can make it even easier if I tell you that I have both the indexing and the match arrays already in arrays in VBA. I actually place them in the spreadsheet in order to use application.match/application.index. I have to do that because those functions rely on a spreadhseet range. I couldn't find a way to use the array already in VBA as the range. It really is inconvenient as I have the array, I have to place it in the spreadsheet, then I have to reference the array once every loop, and then I have to place the new arrays back in the spreadsheet.

    Any suggestions based on that? Again, I can try to explain better if that is necessary.

    Thanks

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Fast Index/Match Alternative in VBA

    Hello RS15,

    Rather than try to explain the problem, the data, the layout, etc., why not post a copy of the workbook? If it contains any sensitive information, redact it before you post.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Registered User
    Join Date
    04-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Fast Index/Match Alternative in VBA

    Here is a dumbed down version of my spreadsheet.

    FB test.xls

    I marked with a comment the loop that is slowing everything down. It should run a little faster than described above because I took out a bunch of stuff and it will have to go through this twice. However, I believe that it is the index/match section in the loop that is slowing everything down. If you need any explanation of what is going on please let me know. If anyone can help me make this run faster/more efficient that would be amazing! And I would be ever grateful!

    Thanks

  7. #7
    Registered User
    Join Date
    04-14-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    66

    Re: Fast Index/Match Alternative in VBA

    I forgot to mention it's module 1

+ 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: 6
    Last Post: 04-30-2014, 02:42 AM
  2. Replies: 1
    Last Post: 06-25-2013, 04:13 AM
  3. UDF Lookup function as an alternative to array functions & match/index
    By Andrew_Harris in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-15-2012, 09:34 PM
  4. [SOLVED] Index & Match Alternative?
    By jeversf in forum Excel General
    Replies: 2
    Last Post: 04-02-2012, 01:58 AM
  5. Replies: 3
    Last Post: 06-14-2011, 08:16 AM

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