+ Reply to Thread
Results 1 to 9 of 9

Slow Copy and Paste

  1. #1
    Registered User
    Join Date
    05-03-2012
    Location
    oymbiti fabbath
    MS-Off Ver
    Excel 2007
    Posts
    4

    Slow Copy and Paste

    I've looked at dozens of solutions to slow VBA/macro copying and pasting, but most of the problems are way beyond what I'm doing, and I just can't get this basic function to work without exponentially slowing down.

    I have a "Main" sheet from which I can push any of several buttons to run a macro (that I simply recorded). Each macro should copy another sheet (numbered 1 through 20), and paste it to a sheet called "D", then clear all contents of the numbered sheet. Here's what I have (for copying, for example "2" and pasting to "D", then clearing "2"):

    Sub Pull2()
    '
    ' Pull2 Macro
    '

    '
    Sheets("2").Select
    Cells.Select
    Selection.Copy
    Sheets("D").Select
    Cells.Select
    ActiveSheet.Paste
    Sheets("2").Select
    Cells.Select
    ActiveSheet.ClearContents
    Sheets("Main").Select
    End Sub

    Then I have a button for returning "D" to "2", which is just vice versa of the first macro. This works exactly as I want it, but after pushing the buttons a couple times the loading time gets longer and longer. I've also tried using the CutCopyMode = False function after the macro to try to clear out the clipboard after each execution, but that doesn't help.

    Another thing I tried for avoiding the clipboard was:

    Sheet4.Range("A1:CZ400").Copy Destination:=Sheet2.Range("A1:CZ400")
    Sheet4.Range("A1:CZ400").ClearContents

    The same thing happens. The first time I try pulling a numbered sheet to sheet "D", and then returning it, it works great, but after 3 or 4 times it becomes ridiculously slow, or never finishes loading. After each of these copy/pastes if I manually go the "D" or "1" or "2", etc, then the sheet takes a exponentially longer time to load. My guess is there's a better way to do this, so that's why I'm here asking for everyone's assistance.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Slow Copy and Paste

    Hi DukeRondo,

    Could you please upload an example Workbook of your problem, macros and all, so we can see how best to solve your issue.

  3. #3
    Registered User
    Join Date
    05-03-2012
    Location
    oymbiti fabbath
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Slow Copy and Paste

    Actually...this is for a game I'm making. It's an RPG type game based in old Japan. It's in fairly early development, but we prefer to have Excel calculate things for us than to roll dice. I hope my Excel helpers don't drop off after learning that this is just for a game and not something "important".

    I'm attaching the game (though I had to delete tons of stuff on it to get it under 1 M to fit on this site), if you want to look at it. The Main page has the "Select Defender" and "Return Defender" buttons. There are actually 80 buttons which take turns appearing/disappearing based on which defender is selected. If you push "Select Defender" and then "Return Defender" a couple times you'll see that it works in the way I want it, but just gets slower each time those buttons are pushed, and then manually clicking on the pages also becomes terribly slow.

    Let me know what you guys think (of the problem, not the game).
    Attached Files Attached Files

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Slow Copy and Paste

    you should try "aligning" values ( i think that's the jargin )


    for example replace the following type of statement:
    Sheet4.Range("A1:CZ400").Copy Destination:=Sheet2.Range("A1:CZ400")

    with:
    Sheet2.Range("A1:CZ400").value = Sheet4.Range("A1:CZ400").value

    Then there is no copy/paste/end-cutcopymode slow down.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Slow Copy and Paste

    I agree with GeneralDisarray,

    for example replace the following type of statement:
    Sheet4.Range("A1:CZ400").Copy Destination:=Sheet2.Range("A1:CZ400")
    with
    Sheet2.Range("A1:CZ400").value = Sheet4.Range("A1:CZ400").value
    And then

    Please Login or Register  to view this content.
    Hope it helps
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  6. #6
    Registered User
    Join Date
    05-03-2012
    Location
    oymbiti fabbath
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Slow Copy and Paste

    This code works fast! Sadly, the pages that were copied/pasted were a combination of values and formulas. This only sends values to the other page. I need to preserve the formulas with this as well.

  7. #7
    Registered User
    Join Date
    05-03-2012
    Location
    oymbiti fabbath
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Slow Copy and Paste

    I replaced Value with Formula, and now I think we're good! I somehow thought code like this would just make references to do other sheet, but it's basically the same as cut and paste, except without a clipboard.

    Thanks everyone! I'll let you know what problems I have next. haha

  8. #8
    Registered User
    Join Date
    06-27-2014
    Location
    San Francisco
    MS-Off Ver
    2007
    Posts
    1

    Re: Slow Copy and Paste

    I am having a similar problem, but NOT only do certain sheets lag when i try to copy and paste (and insert new rows) but sometimes it just crashes all together. my file has about 17 sheets, all of which have about 825 rows of data. not all the sheets lag, just a few, but when they do depending on how much information I have copied onto the clipboard, the whole application crashes. Can someone help?

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Slow Copy and Paste

    Hello Excel_nub,

    Welcome to the Forum,

    There could be a variety of causes.

    Also, Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

    You are more likely to get much faster responses if you could attach a sample workbook in your own Thread as well. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    Regards.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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