+ Reply to Thread
Results 1 to 5 of 5

Alternatives to using a for loop in cunjunction with vlookup

  1. #1
    Registered User
    Join Date
    06-17-2012
    Location
    California
    MS-Off Ver
    2010
    Posts
    5

    Alternatives to using a for loop in cunjunction with vlookup

    I have sheets A, B, C the information in sheet A (contains about 15,000 rows) is constant, Sheet B is Dynamic (contains about 15,000 rows but is usually filtered to about 60-600 rows), and sheet C is where i wish to pool information from both sheets (will typically hold the same amount of rows as sheet B after its been filtered).

    So once the data from sheet b has been pasted to sheet c, now I need sheet c to be populated with the data from sheet A. To do this i use a for loop along with a vlookup (baed on an ID# that is common in all sheets), the code looks something like this

    for x = 1 to y (y being set to last row with data)
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    I know the formula isn't exact and the syntax is a bit off i'm kind of going of memory as I left the file at work, but I hope the gist of it. Ofcourse I need more than just one column from sheet A (its actually more like 6), and i just rinse and repeat to populate the rest of the columns. The formula I have works, it just take about 5 minutes to run, my question is if there is a better alternative to the for loop (as i think that is what slows everything down) also is the fact that i'm looping through and seting the formula for the current cell have anything to do with it? Like I said I'm just looking to reduce the time of this macro, I will try and put more info tomorrow from work if u need it thanks for the help.

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Alternatives to using a for loop in cunjunction with vlookup

    Sounds like advanced filter for me.

    http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx

  3. #3
    Registered User
    Join Date
    06-17-2012
    Location
    California
    MS-Off Ver
    2010
    Posts
    5

    Re: Alternatives to using a for loop in cunjunction with vlookup

    went from 5 minutes to 17 seconds using these babies:

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Now I'm having a problem with curcell which is dimed as a range.

    so my code reads :

    Please Login or Register  to view this content.
    I keep getting a type mismatch error highlighting the first line in this code. Any suggestions?

  4. #4
    Registered User
    Join Date
    06-17-2012
    Location
    California
    MS-Off Ver
    2010
    Posts
    5

    Re: Alternatives to using a for loop in cunjunction with vlookup

    Never Mind I Fixed it, the vlookup was looking for an empty cell derp....

  5. #5
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Alternatives to using a for loop in cunjunction with vlookup

    @ Bobcat1

    Based on your last post it seems that your issue has been resolved but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

+ 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