+ Reply to Thread
Results 1 to 7 of 7

Speed up copy paste macro

  1. #1
    Registered User
    Join Date
    05-26-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2007
    Posts
    10

    Speed up copy paste macro

    Hi Everyone,

    I'm asking for some assistance again.

    I have the code below that in part works but needs a little of your expertise in tweaking.
    1. It runs to slow and the screen flashes, I have screen updating turned off but cant get it to run smoother?
    2. It searched the entire document in column '"L", can I set a range of L3:L100, because the sheet doesn't have that much data?

    Thanks again, Brad.



    [Code]Sub SearchForString()
    Dim LSearchRow As Integer
    Dim LCopyToRow As Integer

    On Error GoTo Err_Execute
    ScreenUpdating = False

    Sheets("Sheet2").Visible = True
    Sheets("Sheet2").Select
    Range("B3:K100").Select
    Selection.Delete

    Sheets("Sheet1").Select

    LSearchRow = 3
    LCopyToRow = 3

    While Len(Range("l" & CStr(LSearchRow)).Value) < 7
    If Range("l" & CStr(LSearchRow)).Value < 7 Then

    i = 1


    Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Range(Cells(i, 1), Cells(i, 11)).Select
    Selection.Copy

    Sheets("Sheet2").Select
    Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
    ActiveSheet.Paste
    LCopyToRow = LCopyToRow + 1

    Sheets("Sheet1").Select

    End If

    LSearchRow = LSearchRow + 1

    Wend

    Application.CutCopyMode = False
    Sheets("Sheet2").Select
    Range("A3").Select

    MsgBox "All matching data has been copied."
    ScreenUpdating = True

    Exit Sub
    Err_Execute:
    MsgBox "An error occurred."

    End Sub[Code]
    Last edited by Brado; 02-21-2021 at 11:17 PM. Reason: Add code tags

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,719

    Re: Speed up copy paste macro

    While people are looking for a solution for you, maybe you could read the Forum Rules again and act on #2.

    After you've done that, explain in detail what you want to achieve.
    Non working code is quite often more a hindrance than anything else.
    Last edited by jolivanes; 02-21-2021 at 11:11 PM.

  3. #3
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Speed up copy paste macro

    Please also provide a sample file as per the yellow banner above with your explanation.

  4. #4
    Registered User
    Join Date
    05-26-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2007
    Posts
    10

    Re: Speed up copy paste macro

    Hi All,

    Workbook attached.

    Thanks, Brad
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Speed up copy paste macro

    Give this a try

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-26-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2007
    Posts
    10

    Re: Speed up copy paste macro

    Great works fine, thank-you.

    And thanks for the patience

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,719

    Re: Speed up copy paste macro

    Your attachment does not tell us much. Still waiting on an explanation of what to do.

    At the top of your Module, add
    Option Explicit
    Add
    Please Login or Register  to view this content.
    Wherever you have Sheets("Sheet2"), replace it with sh2. Same for Sheets("Sheet1"), replace that with sh1

    Re: It searched the entire document in column '"L", can I set a range of L3:L100, because the sheet doesn't have that much data?
    Instead of Range("L3:L100")
    use
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Does it need deleting? Or just clearing? Selecting is a NoNO most of the time and is very seldom required.
    The 4 lines should be replaced by
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.

+ 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. 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
  2. [SOLVED] VBA macro to copy specific rows - how to speed up the process?
    By AndersThyme in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-04-2018, 08:00 AM
  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

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