+ Reply to Thread
Results 1 to 5 of 5

Copy Paste Loop slows down over time

  1. #1
    Registered User
    Join Date
    09-05-2012
    Location
    NYC
    MS-Off Ver
    Microsoft 365 (Version 2304, 64-Bit), Win11
    Posts
    23

    Copy Paste Loop slows down over time

    Hi everyone,
    I have a macro that populates a spreadsheet with a lot of bloomberg data (using BDP formulas) and a separate macro that copies/pastes values to lock down this data before creating reports with it. The copy/paste operation can take several minutes to complete. To monitor this and whether or not the macro is hanging (the file is huge and can occasionally crash), I am using a loop to go through the rows one by one and copy paste values on each, while updating the statusbar to tell me what row is being worked on. The issue that I am noticing is that the macro slows down over time. For example, it starts working at ~100 rows per second, slow to about 50 rows per second, then 40..30..20..and settles around 10 per second, which is a huge decrease in speed from beginning to end.

    I fully understand that the loop+statusbar is not the fastest way to perform the operation, especially updating the statusbar every row, but I prefer this to raw overall speed as it lets me monitor the progress and know if the file is crashing. My question is why the operation slows down over time. If anything, I would think that it would speed up towards the end as thousands of rows above have been converted from formulas to values, which reduces the file size considerably at the end (but maybe not until I save?). It seems like something is building up in memory or dependency tables or something the longer it runs and this is slowing it to a crawl by the end. Any ideas what this could be or suggestions for obtaining more consistent speed throughout the operation? One thing to note is that if I run it a second time after the formula cells have already been pasted as values, it runs perfectly fine... fast and consistent speed through all rows. Here is my code:

    Please Login or Register  to view this content.
    Last edited by ugabrew; 04-15-2016 at 10:02 AM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy Paste Loop slows down over time

    Maybe:


    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    09-05-2012
    Location
    NYC
    MS-Off Ver
    Microsoft 365 (Version 2304, 64-Bit), Win11
    Posts
    23

    Re: Copy Paste Loop slows down over time

    That code works, and is probably faster than mine, but doesn't allow me to monitor the progress like my code above with the statusbar updates. I'm primarily trying to figure out why mine is slowing down over time, as if something is building up in memory.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Copy Paste Loop slows down over time

    Try something like:

    Please Login or Register  to view this content.
    to see if it's the status bar backing up

  5. #5
    Registered User
    Join Date
    09-05-2012
    Location
    NYC
    MS-Off Ver
    Microsoft 365 (Version 2304, 64-Bit), Win11
    Posts
    23

    Re: Copy Paste Loop slows down over time

    Thanks for the suggestion, but that doesn't seem to speed things up or deal with the slowdown over time. As I mentioned, running the macro a second time once the formulas are gone seems to work fine, with even speed throughout thousands of rows. This is why I don't think it is the StatusBar. I am wondering if it has something to do with the dependency tree and excel trying to update that for all of the cells that have been modified so that it can perform its 'smart calculation' at the end rather than recalculating every single cell. This topic is discussed here: https://fastexcel.wordpress.com/2015...ulation-speed/. The suggestion in that post is that you can disable these dependency tree updates with "Workbook.ForceFullcalculation=True" and that in some cases it may be faster. The downsides seem to be that this setting exists at the application level and affects all other workbooks, not just the one you put the code in, and it remains in affect until you close the Excel application. Any ideas if that could be the relevant to my slowdown issue?
    Last edited by ugabrew; 04-15-2016 at 02:54 PM.

+ 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. [SOLVED] Copy Paste Loop
    By ayvee0 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-31-2013, 04:31 PM
  2. [SOLVED] Destination copy and paste (values only) for copy loop
    By mr_mango81 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2013, 08:59 PM
  3. [SOLVED] Copy Paste Loop ends before copy/paste is finished
    By brgr4u in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-08-2013, 04:01 PM
  4. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  5. Copy and paste named range at end of loop causing massive slowdown over time
    By Sccye in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-12-2013, 07:03 AM
  6. [SOLVED] VBA loop copy/paste
    By barrec in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-06-2012, 04:21 PM
  7. Copy and Paste with a loop
    By abhitullu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2011, 02:14 AM
  8. Excel 2007 : Macro - loop slows down
    By IALTO in forum Excel General
    Replies: 17
    Last Post: 05-20-2010, 12:50 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