+ Reply to Thread
Results 1 to 2 of 2

Speed Up Copy & Paste to New Row Macro

  1. #1
    Registered User
    Join Date
    10-15-2018
    Location
    London, England
    MS-Off Ver
    365
    Posts
    75

    Speed Up Copy & Paste to New Row Macro

    Hi All,,

    I have thrown together a basic looped 'copy & paste values to new row' module based on online research. The below script takes approx. 35 seconds to complete and this time, I assume, is mainly due to each time CZ27 + 0.01 occurs within the loop 1000's of cell formulas recalculate. But I assume that using copy and pastespecial functions reduce the speed further and was hoping someone could please streamline this. Thank you in advance


    Option Explicit

    Sub Backtest_Improved()

    Dim StartTime As Double
    Dim SecondsElapsed As Double

    Application.ScreenUpdating = False
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet
    Dim i

    Set copySheet = Worksheets("Model - BBW+MFI")
    Set pasteSheet = Worksheets("VBA Report")

    StartTime = Timer

    'Reset all relevant variables back to default

    Sheets("Model - BBW+MFI").Range("CZ20").Value = "2"
    Sheets("Model - BBW+MFI").Range("CQ5").Value = "2%"
    Sheets("Model - BBW+MFI").Range("CZ27").Value = "0.05"

    'Loop BBW increase by 0.01

    For i = 0 To 7

    copySheet.Range("EM3:FU3").Copy
    pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

    Sheets("Model - BBW+MFI").Range("CZ27") = Sheets("Model - BBW+MFI").Range("CZ27") + 0.01

    'Debug.Print i

    Next i

    Sheets("Model - BBW+MFI").Range("CZ27") = Sheets("Model - BBW+MFI").Range("CZ27") - 0.01

    SecondsElapsed = Round(Timer - StartTime, 2)
    MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation

    Application.CutCopyMode = False
    Application.ScreenUpdating = True

    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,604

    Re: Speed Up Copy & Paste to New Row Macro

    Please Login or Register  to view this content.
    Ben Van Johnson

+ 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 copy paste macro
    By Brado in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-22-2021, 12:42 AM
  2. Replace Code to improve processing speed for copy & paste
    By paula.mccall in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-29-2019, 01:04 PM
  3. [SOLVED] speed up copy/paste macro
    By peter_swe in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-02-2016, 06:05 AM
  4. How to speed up a copy and paste macro
    By Freedom Call in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-30-2016, 08:41 AM
  5. Copy Paste Formulas - Any Speed Tips?
    By killerkoz17 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 02-23-2014, 07:40 AM
  6. speed - variables vs copy paste
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2008, 03:34 PM

Tags for this Thread

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