+ Reply to Thread
Results 1 to 2 of 2

How can I make this copy paste function faster???

Hybrid View

  1. #1
    Registered User
    Join Date
    04-05-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    How can I make this copy paste function faster???

    Hi,

    I am trying to make this code run quicker but am not very familiar with VBA. Any help is much appreciated. Thank you.

    Function midterm(wksName As String, row_Src As Long, column_Dst As String, srch_Term As String)
        Application.ScreenUpdating = False
        
        Worksheets(wksName).Activate
        Range(Cells(row_Src, 1), Cells(row_Src, 10)).Select
        Selection.Copy
        
        Worksheets("midterm").Activate
        Cells(2, 1).Select
        Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        
    End Function
    The code is taking a range from one worksheet and moving that range to another location but when I run this code over several thousand lines it takes forever. Is there any way to make it quicker? Thank you again for your help.

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: How can I make this copy paste function faster???

    Is there a reason it is a function rather than a sub?

    I would propose (and the following assumes that your current calculation mode is set to automatic (Excel Options >> Formulas >> Calculation Options >> Advanced = True):

    Function midterm(wksName As String, row_Src As Long, column_Dst As String, srch_Term As String)
    
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Application.Calculation = xlCalculationManual    
    
           Worksheets(wksName).Range(Cells(row_Src, 1), Cells(row_Src, 10).Copy
           Worksheets("midterm").Cells(2, 1).PasteSpecial Paste:=xlValues, _
                      Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    
        Application.ScreenUpdating = True
        Application.EnableEvents = True
        Application.Calculation = xlCalculationAutomatic    
    
    End Function
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

+ 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