Results 1 to 5 of 5

Copy Paste Loop slows down over time

Threaded View

ugabrew Copy Paste Loop slows down... 04-15-2016, 10:00 AM
xladept Re: Copy Paste Loop slows... 04-15-2016, 11:10 AM
ugabrew Re: Copy Paste Loop slows... 04-15-2016, 11:23 AM
xladept Re: Copy Paste Loop slows... 04-15-2016, 11:45 AM
ugabrew Re: Copy Paste Loop slows... 04-15-2016, 02:51 PM
  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:

    Sub CopyPasteValues()
    
        Dim wbms As Workbook
        Set wbms = ThisWorkbook
        
        wbms.Sheets("Formulas").Activate
        Application.Calculation = xlCalculationManual
        
    'Set variables
        Sheets("Macro").Calculate
        StartRow = Sheets("Macro").Cells(2, 3)
        EndRow = Sheets("Macro").Cells(3, 3)
        HeaderRow = wbms.Sheets("Macro").Cells(7, 3)
        AverageFlagRow = wbms.Sheets("Macro").Cells(8, 3)
        FormulaRow = Sheets("Macro").Cells(4, 3)
        StartFormulaCol = Sheets("Macro").Cells(5, 3)
        EndFormulaCol = Sheets("Macro").Cells(6, 3)
    
    'Copy/paste values
        i = StartRow
        Do Until i > EndRow
            Range(Cells(i, 1), Cells(i, EndFormulaCol)).Value = Range(Cells(i, 1), Cells(i, EndFormulaCol)).Value
            Application.StatusBar = "Copy/Pasting row: " & i & "."
            DoEvents
            i = i + 1
        Loop
        
    'Finalize
        Application.StatusBar = False
        Application.Calculation = xlCalculationAutomatic
        Range("A1").Select
            
    End Sub
    Last edited by ugabrew; 04-15-2016 at 10:02 AM.

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