+ Reply to Thread
Results 1 to 13 of 13

Inserting blank rows now running very slow

  1. #1
    Forum Contributor
    Join Date
    12-15-2009
    Location
    Herndon, VA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Inserting blank rows now running very slow

    This block of code inserts a blank row at every change in column A. The loop begins at the bottom. This used to run extremely fast. Now it's slow. Any ideas why?



    Please Login or Register  to view this content.
    There is other code in this procedure. For some reason it takes a long time. When I run this code in its own procedure it zips right thru.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Inserting blank rows now running very slow

    Hi there,

    See if setting the calculation to manual (and then resetting it back to its original setting) helps i.e.

    Please Login or Register  to view this content.
    From Excel 2007 and on it's a good idea to not use an integer variable when referencing rows as its highest value is 32,767 as opposed to there being 1,048,576 rows in Excel 2007 and on.

    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Inserting blank rows now running very slow

    Quote Originally Posted by Excel_vba View Post
    This block of code inserts a blank row at every change in column A.
    The way the question is posted might be an event code? If thats the case I would just add one more thing to the amazing code Trebor76 provided.

    Please Login or Register  to view this content.
    Thanks

  4. #4
    Forum Contributor
    Join Date
    12-15-2009
    Location
    Herndon, VA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Inserting blank rows now running very slow

    Quote Originally Posted by fredlo2010 View Post
    The way the question is posted might be an event code? If thats the case I would just add one more thing to the amazing code Trebor76 provided.
    What do you mean by event code?

  5. #5
    Forum Contributor
    Join Date
    12-15-2009
    Location
    Herndon, VA
    MS-Off Ver
    Excel 2010
    Posts
    163

    Re: Inserting blank rows now running very slow

    Quote Originally Posted by Trebor76 View Post
    From Excel 2007 and on it's a good idea to not use an integer variable when referencing rows as its highest value is 32,767 as opposed to there being 1,048,576 rows in Excel 2007 and on.
    Robert
    Nice suggestion. I didn't even think about that. I hope I will keep that in mind.

    I tried your code and it still takes the same amount of time to execute. Any other ideas? Does memory need to be cleared out or something?

    Also, I noticed that in your code you turn off/then turn on screen updating. Is there an advantage to doing this?

  6. #6
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Inserting blank rows now running very slow

    A code thats controlled by and event is placed under the Sheet module or Thisworkbook. They are triggered by changes in the worksheet. For example if the even is triggered every time the sheet is calculated the code will run.

    Did you tried my code? Can you provide us with a sample of the workbook ?

    The code Trebor provided turns off calculations (set them to manual , and then back to whatever state it was on) so the formulas do not have to refresh and use memory. It also turns off screen updating so it does not use as much memory repainting and showing updated material.

    At this point the code should be bulletproof lol can you attach a sample of your workbook. Maybe there is something we are missing.

    Thanks


    Thanks

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Inserting blank rows now running very slow

    Try this
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Inserting blank rows now running very slow

    the amazing code Trebor76 provided
    Thanks fredlo2010 - not much compared to some of the code provided on this forum (jindon is a perfect example) but nice of you to say so

    Cheers,

    Robert

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

    Re: Inserting blank rows now running very slow

    Just for the heck of it.
    Don't take this wrong please as I certainly can't compete writing code with you people.
    Filled 50,000 rows in blocks of 10, (every 10th row the value changes).
    Ran all three codes twice each with a timer and got the following.
    Trebor76 first code, resp. 16.05 and 14.17 seconds
    Trebor76 second code (the code from fredlo2010's post) resp 11.61 and 12.36 seconds
    jindon's code resp 19.48 and 20.56 seconds.
    This is on a +/- 7 year old machine with 2 GB Ram and a 2.4 GHz CPU.

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Inserting blank rows now running very slow

    Thanks for the analysis jolivanes!!

    The If statement can also be slightly refined into a single line which will save more time as follows:

    Please Login or Register  to view this content.
    Regards,

    Robert

  11. #11
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Inserting blank rows now running very slow

    @jolivanes,

    as being already set up with test data and timing, perhaps you'd like to consider this one
    Please Login or Register  to view this content.
    Last edited by kalak; 12-23-2013 at 05:59 AM.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Inserting blank rows now running very slow

    Try this one then
    Please Login or Register  to view this content.

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

    Re: Inserting blank rows now running very slow

    OK Gentlemen, here is what I got. (see attached as your machine is probably from this century)

    Trebor76 (Post #2) resp 11.70 and 9.86 seconds
    Trebor76 (Post #2, with suggestion fredlo 2010) resp 13.05 and 14.84 seconds
    Trebor76 (Post #10, with suggestion fredlo 2010) resp 16.66 and 18.52 seconds
    jindon (Post #7) resp 27.06 and 29.86 seconds
    jindon (Post #12) resp 0.39 and 0.39 seconds
    kalak (Post #11) resp 0.61 and 0.61 seconds
    Attached Files Attached Files

+ 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 is running real slow and makes navigating the worksheet really slow after execution.
    By MichWolverines in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2013, 04:29 PM
  2. [SOLVED] very slow macro (delete blank rows)
    By Danielle22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2013, 04:13 AM
  3. Slow Running Code when Inserting Column
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2013, 04:23 PM
  4. Inserting blank rows
    By tekiert1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-23-2009, 06:35 PM
  5. Inserting Blank rows after every row upto 2500 rows
    By Manju in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-22-2006, 08:00 AM

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