+ Reply to Thread
Results 1 to 16 of 16

Array looping, increase speed of array macro

  1. #1
    Registered User
    Join Date
    11-22-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Array looping, increase speed of array macro

    I have two sheets, the array macro below detects the last row, then indexes column D, then matches data from column A on Sheet1 to column A on Sheet2 and matches column B on sheet 1 to column E on Sheet2. Then it returns the corresponding value from the indexed column to column G on Sheet1 if the value exists. The macro works fine however I am not advanced enough to make it work faster. Sheet2 contains over 270K rows to search through and it takes quite a long time with 50k rows on Sheet1. Is there a way to make this loop through the records to speed up the process? or in general make the returns faster?
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 11-22-2013 at 01:41 PM. Reason: Added Code Tags

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Array looping, increase speed of array macro

    You could do it like this:
    Please Login or Register  to view this content.
    ?

  3. #3
    Registered User
    Join Date
    11-22-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Array looping, increase speed of array macro

    Thanks Yudlugar but this did not work.

    I may not be clear in my statement, The macro works, I need it to loop or in some form work faster without brining my CPU useage to 100%. The macro you provided replaces my header (G1) and only returns the same value that was placed in my header in (G2). If I can provide more information please let me know.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Array looping, increase speed of array macro

    I'm not sure if there is a quicker way than the worksheet fucntions. You could maybe try something along the lines of this, based on using find to loop through the data but dependant on what your data is like it might not be any better.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-22-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Array looping, increase speed of array macro

    Thanks again Yudlugar,

    Can you show me how to put that in with my code?

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Array looping, increase speed of array macro

    It was to replace your code.

  7. #7
    Registered User
    Join Date
    11-22-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Array looping, increase speed of array macro

    I receive a compile error on this line, says "Sub or Function not defined"


    Set counta = FindNext(counta)

    Error on FindNext

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Array looping, increase speed of array macro

    try changing it to:
    set counta = Sheets("Sheet2").Range("A:A").findnext(counta)

  9. #9
    Registered User
    Join Date
    11-22-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Array looping, increase speed of array macro

    I really appreciate all your work, however this code actually returns a Run-time error2013-11-25_0948.png

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Array looping, increase speed of array macro

    Can you upload a sample workbook please.

    Click go advanced and then "manage attachments"

  11. #11
    Registered User
    Join Date
    11-22-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Array looping, increase speed of array macro

    I hope this works, I had to knock down the size and had to remove modules and formatting. Also there should be an empty column on sheet 1 between E and F.
    Attached Files Attached Files
    Last edited by techrcn; 11-25-2013 at 12:28 PM.

  12. #12
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Array looping, increase speed of array macro

    Please Login or Register  to view this content.
    That seems to work on your example.

  13. #13
    Registered User
    Join Date
    11-22-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Array looping, increase speed of array macro

    At a large scale it seems to work a little faster, its not eating up the processor as much as the old one did. Thanks again, I'll see what I can manage.

  14. #14
    Registered User
    Join Date
    11-22-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Array looping, increase speed of array macro

    Yudlugar,

    It seems to lock up if data in sheet 1 is not found on sheet 2. Is there an else statement I can put in there?
    Last edited by techrcn; 11-26-2013 at 09:35 AM.

  15. #15
    Registered User
    Join Date
    11-22-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Array looping, increase speed of array macro

    Yudlugar,

    It seems to lock up if data in sheet 1 is not found on sheet 2. Is there an else statement I can put in there?

  16. #16
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Array looping, increase speed of array macro

    You could maybe try putting a counter in and then exiting if it has searched more than the count, for example
    Please Login or Register  to view this content.
    change i>500 as neccessary

+ 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. speed up sum if array formula with VBA??
    By jed38 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-30-2013, 01:32 PM
  2. How to speed up this macro? How to use an array?
    By djvino in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-15-2012, 07:39 AM
  3. Speed up max if array
    By reddwarf in forum Excel General
    Replies: 9
    Last Post: 03-02-2011, 08:20 AM
  4. Will an Array speed this up?
    By Mase in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2005, 06:53 AM
  5. [SOLVED] Increase macro speed?
    By Valeria in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2005, 05:06 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