+ Reply to Thread
Results 1 to 7 of 7

How to insert rows at constant intervals in a large worksheet quickly?

  1. #1
    Registered User
    Join Date
    02-05-2018
    Location
    Brisbane, Australia
    MS-Off Ver
    2013
    Posts
    3

    How to insert rows at constant intervals in a large worksheet quickly?

    Hi there,

    For Excel 2013, I have a sheet with about 10,000+ rows, each of which contains 63 columns filled with data. I'm trying to add a new row at certain intervals in the sheet. The first time I want to do this is at row 9, followed by intervals of 8, until the end of the sequence of data. I also need to add a bit of formatting to each new row produced.

    I am currently using a loop for this. While this works and does what I want it to, it is agonisingly slow and crashes fairly frequently if I try to update the entire sheet. I was wondering if anyone has any idea or alternative of how to do this process quickly? (I've seen online examples using arrays that add rows quickly, but I'm fairly new to VBA and struggle to understand or reverse engineer them.)

    I've included my code in case you want a clearer picture of what I'm doing. Any help is much appreciated!

    Please Login or Register  to view this content.

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

    Re: How to insert rows at constant intervals in a large worksheet quickly?

    You don't, or should not anyway, delete or insert from the top on down. Always from the bottom up.
    It would look like this:
    Please Login or Register  to view this content.
    The problem would be to find out where to start at the bottom so you'll end up at row 9.
    Once you have that sussed, let us know if it still crashes. You could than use specialcells(xlTypeBlanks) to use the formatting.
    I would say that the formatting is the culprit as that is a known slow process.
    They suggested to me once years ago to use a template instead of formatting a large range.
    See how far you get.
    Last edited by jolivanes; 02-05-2018 at 10:30 PM. Reason: code tags

  3. #3
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: How to insert rows at constant intervals in a large worksheet quickly?

    replace with this to see if it is quicker

    Please Login or Register  to view this content.
    Happy with my advice? Click on the * reputation button below

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

    Re: How to insert rows at constant intervals in a large worksheet quickly?

    One way
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    12-22-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    532

    Re: How to insert rows at constant intervals in a large worksheet quickly?

    @Steingar
    11500/7 will more than 1.5k rows changes. Use sort is fast than insert. Guru Jindon his code should the fastest.

  6. #6
    Registered User
    Join Date
    02-05-2018
    Location
    Brisbane, Australia
    MS-Off Ver
    2013
    Posts
    3

    Re: How to insert rows at constant intervals in a large worksheet quickly?

    Hi all,

    I tried what you all recommended and I found the following:

    @Jindon your code worked great! There were a few aspects out of wack, like the number of rows inserted and where the sequence started, but with a bit of fiddling I've got it to suit my requirements. Thank you so much for your recommendation, and the problem is now solved.

    @Crooza I wasn't able to get your code to work satisfactory unfortunately, but thanks for your comment.

    @jolivanes I've taken what you said about working backwards on-board when it comes to adding/deleting rows, and I understand the reason why, so thanks for the recommendation! As an aside, I set up a timer for my program and found that the difference between running the loop without formatting vs. with formatting was negligible, so it appears that the bottleneck was with adding the rows and not the formatting as was theorised.

    Once again, thanks for everyone's help, and purely for interest's sake and any future googlers, the correctly altered code is as follows:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: How to insert rows at constant intervals in a large worksheet quickly?

    It works for smaller ranges but if the range gets too big it fails due to the length of the text string

+ 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. I need to insert blank rows into a large spreadsheet.
    By naffie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-12-2013, 07:18 PM
  2. Replies: 3
    Last Post: 04-26-2011, 05:12 PM
  3. How to quickly copy down in very large file?
    By excel0123 in forum Excel General
    Replies: 7
    Last Post: 10-05-2009, 08:52 PM
  4. quickly updating a large group of formulas
    By fantom06 in forum Excel General
    Replies: 2
    Last Post: 04-01-2009, 09:05 AM
  5. Linear Interpolation between non constant intervals
    By gpktm in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-19-2007, 03:34 PM
  6. Replies: 0
    Last Post: 04-24-2006, 08:45 AM
  7. [SOLVED] How to quickly insert a blank row every 5 rows?
    By Med in forum Excel General
    Replies: 2
    Last Post: 09-09-2005, 08:05 PM

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