+ Reply to Thread
Results 1 to 9 of 9

Copy/Paste Macro Bugs the File

  1. #1
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    5

    Copy/Paste Macro Bugs the File

    Hi,

    I have a copy/paste VBA script in my workbook but it completly bug my file when it's executed.

    Here is a link to my workbook.

    https://drive.google.com/file/d/0B6a...it?usp=sharing

    The bug appears when I select "Q1,Q2,Q3,Q4 or Total" in my sheet "Tableau des défauts".

    I use Excel 2007 and my computer has a strong enough processor.

    Olivier

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Copy/Paste Macro Bugs the File

    Any event code should have appropriate Error Handling:

    First line:

    On Error Goto ErrHandler:

    'Other code

    'Last lines
    ErrHandler:
    Application.EnableEvents = True
    End Sub


    And should start with the second line:

    Application.EnableEvents = False

    and make sure that before any Exit Sub lines you use

    Application.EnableEvents = True

    Otherwise, you risk getting into infinite loops that will bog down even the most powerful machines

    And if you have event code, you may want to use the same logic in other macros - depends on what you want to have happen....
    Last edited by Bernie Deitrick; 08-07-2014 at 12:30 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    5

    Re: Copy/Paste Macro Bugs the File

    Thank you for your answer Bernie. I made the corrections but I'm still stuck in an infinite loop. Here is the new code:


    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Copy/Paste Macro Bugs the File

    You're doing way too much looping. Try changing (typical, for all your loops):

    Please Login or Register  to view this content.
    to just this, to copy the cells as blocks (I think the A range should be copied to ws as well.....)


    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    5

    Re: Copy/Paste Macro Bugs the File

    The code seems well written but when I try it, nothing is copied. I don't have my bug but it still doesn't work properly. I also tested to put my code in a button and it's the same infinite loop.
    Last edited by Olibouch; 08-07-2014 at 02:13 PM.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Copy/Paste Macro Bugs the File

    Your code only copies from Sheets "Avril", "Mai", and "Juin", no matter what is chosen. And you did not make the latest changes, anywhere. So the problem is in .... a lot of things, probably. Change the loops as indicated in my last message, and change the sheet names to the correct sheets based on the value selected in E2, then post back.

  7. #7
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    5

    Re: Copy/Paste Macro Bugs the File

    It's because I didn't uploaded the latest version of the file. Here is the link to the new file:

    https://drive.google.com/file/d/0B6a...it?usp=sharing

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,946

    Re: Copy/Paste Macro Bugs the File

    Well, your code worked, but was a little off in clearing the used cells on Calcus - you had data starting in Row 7001, so the new data was being pasted way, way down the sheet. to fix that, change all the 7000s to 70000 or 700000, or even 1048576

    Also, you have a LOT of calculations, so for all your events, use code like this at the top to prevent recalculation with every paste:

    Please Login or Register  to view this content.

    And then finish with

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    5

    Re: Copy/Paste Macro Bugs the File

    Thank you for the time you passed on my problem.

+ 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. macro to copy used range and paste in the body tag of a html file/text file
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 08:34 PM
  2. Macro to copy and paste source file to destination file using cell value
    By mani88 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2013, 10:16 AM
  3. macro to open, copy paste from existing excel file to a new blank file
    By 2blessed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-15-2012, 06:05 PM
  4. macro to open file - copy - then paste into other file possible??
    By Kezwick in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-13-2011, 07:59 AM
  5. Replies: 1
    Last Post: 10-17-2005, 04:05 AM

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