+ Reply to Thread
Results 1 to 24 of 24

Insert multiple rows each specific number of rows

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Insert multiple rows each specific number of rows

    Hello everyone
    In the following code
    Please Login or Register  to view this content.
    it is supposed to insert one empty row between four rows ..

    Need to be able to insert 10 rows instead of one empty row
    Thanks advanced for help
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    I found this code but didn't get exact results too
    Please Login or Register  to view this content.
    I have data starting in row 1 till 1000 (for example)
    Need to insert 10 blank rows between each four rows

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Insert multiple rows each specific number of rows

    Try

    Please Login or Register  to view this content.
    Last edited by jason.b75; 05-21-2016 at 07:02 AM.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    Now I have solved most of it using this code
    Please Login or Register  to view this content.
    It works great but the problem is that it begins from the last row so I got groups of four rows of data and 10 empty rows in between ,, but the first group in the first rows is only of two so i need a way to do the task starting from the first row not the last row

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert multiple rows each specific number of rows

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    Thanks Mr. Jason for reply
    I think it would be better to attach a sample workbook to illustrate my request clearly
    In Columns F:G I attached expected output
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    @Mr. AB33 it doesn't work well for me

  8. #8
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Insert multiple rows each specific number of rows

    Had a slight error in my code, the Step should be 14, not 15 (4 rows of data + 10 blank rows per group).

    I've edited my previous reply to correct the code.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert multiple rows each specific number of rows

    Inserting rows should be best done using backward loops, not forward.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    Great Mr. Jason I have already tested it .. Look carefully at the results .. it worked for two groups only then nothing happened
    I think this number 1.25 would be changed but don't know what it refers to

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    Quote Originally Posted by AB33 View Post
    Inserting rows should be best done using backward loops, not forward.
    Great this is in case we don't know the circumstances .. I need to deal with fixed empty rows and fixed number of rows for each group ..

    In this code
    Please Login or Register  to view this content.
    I changed 1.25 to 10 and now it is working very well as expected
    But need to know what 1.25 refers to .. it is some of manual calculation
    Last edited by YasserKhalil; 05-21-2016 at 07:18 AM.

  12. #12
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Insert multiple rows each specific number of rows

    Oops, I missed that. It's caused by the multiplier used to correct the last row once you start inserting blanks.

    Here's a different approach that doesn't fall foul of that problem.

    Please Login or Register  to view this content.
    I've set the code so that you can change the pattern by adjusting the values of the 3 variables based on the comments in the code.

  13. #13
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    That's great Mr. Jason
    Thank you very much for this wonderful solution

    The code in Post # 11 works too but I need to know what 1.25 refers to and how to automate this number to suit the process of insert?

  14. #14
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    This is my working try too
    Please Login or Register  to view this content.

  15. #15
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Insert multiple rows each specific number of rows

    1.25 is an adjustment to correct the position of the last row.

    If you start with 50 rows of data, the line of code that identifies the last row will only work up to row 50. As you insert blank rows, the last row moves down, but the code still works with the original last row.

    To allow for this you need to predict where the last row will be by calculating the difference between the original number of rows and the number of rows you will have once the code is finished.

    In your original code, you had 4 rows of data, then insert 1 blank row, giving you a total of 5 rows per group. 5/4 = 1.25, which is where the adjustment value comes from.

    With the revised code, it would be 4 rows of data, insert 10 blank rows, total of 14 rows per group, so the adjustment should be 14/4 = 3.25.

    In reality, any number greater than 3.25 would work, which is why your code runs fine when you changed it to 10, it just means that you're running the code on empty rows below the end of the data, effectively bloating the size of your sheet.

    edit:-

    Looking at your code in post #14, I think that you have understood how it works

  16. #16
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    I am shocked ..!
    After trying to apply codes to original file (10,000 rows) the code took about 25 seconds to execute
    Is there a possible way to get it faster .............??

  17. #17
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Insert multiple rows each specific number of rows

    You could try setting calculation to manual while the code runs, but to be fair, I think that 25 seconds sounds reasonable for 10,000 rows.

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    Quote Originally Posted by jason.b75 View Post
    You could try setting calculation to manual while the code runs, but to be fair, I think that 25 seconds sounds reasonable for 10,000 rows.
    Thanks for reply and for post # 15 .. it is great explanation and I changed this line according to your explanation
    Please Login or Register  to view this content.
    As an idea but I don't know if it is possible or not..
    Is it possible to store the rows where the insertion will be and insert empty row in one shot!! I think I am crazy related to this idea

  19. #19
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Insert multiple rows each specific number of rows

    The theory sounds possible, I've made it work for inserting single rows.

    Please Login or Register  to view this content.
    But as soon as you try to resize to insert multiple rows it fails.

    I'm going to be offline now for the rest of the day, hopefully someone else will pick up on the thread, but if not, I will have another look later to see if I can figure something out.

  20. #20
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Insert multiple rows each specific number of rows

    I suggest you to reduce your "shocking state", it is not good for your heart.

    Please Login or Register  to view this content.

  21. #21
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    Thank you very much for this great step ..
    I think it is a good start to the main problem
    Have a nice day and I will wait for you

  22. #22
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    Mr. Karedog
    No No No I am shocked again ... Really shocked of that wonderful and fascinating solution ..
    With your solutions I feel very happy to great extent
    Now it is completely solved in perfect and very speedy way
    You are ROCK
    Thank you very very much and best regards

    Please Can you have a look at this thread as it is related somewhat to this issue
    http://chandoo.org/forum/threads/cop...fic-way.29562/
    Last edited by YasserKhalil; 05-21-2016 at 09:35 AM.

  23. #23
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Insert multiple rows each specific number of rows

    Eh, another shocking state ? Sorry about that.
    You are welcome, and, I am a human, not a rock.
    Excel Forum is the only forum I have account, so I can't download the attachment, hope someone else can help you there.


    Regards

  24. #24
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Insert multiple rows each specific number of rows

    Thanks a lot Mr. Karedog for reply
    I mean with ROCK not the ROCK itself but it has another meaning which is (you rock. You are really great.)
    you rock
    colloq. phr. - expression used to convey admiration, gratitude, and/or affection. Often appears in conversations when one has impressed the other; whether it be by a show of one's talent or skill, or generosity and kindness at heart. Also effectively used in casual conversation as informal expression of love, especially when in the presence of others.
    After a particularly "attentive" evening of lovemaking, the next morning Laura said to Chris, "You rock", while amongst their group of friends, though she was really saying "I love you so much and you are the MAN"
    Thanks a lot for great help
    May I post the same issue here again and refer to the original thread at chandoo?
    I have posted it here again ..
    http://www.excelforum.com/showthread...68#post4392568
    Last edited by YasserKhalil; 05-21-2016 at 10:39 AM.

+ 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. [SOLVED] Macro to insert specific number of rows, populate rows with data above except date
    By Melissa Camp in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-08-2015, 03:59 PM
  2. [SOLVED] Insert Rows on Criteria and Copy content to Specific Cells in New Rows(Tables)
    By TheScott in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2015, 03:38 PM
  3. Replies: 0
    Last Post: 03-06-2013, 05:44 PM
  4. [SOLVED] Insert Multiple Rows Based Off Number in Cell and Copy Data From Above New Rows
    By tstell1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2012, 04:15 PM
  5. Need Macro to insert a Specific number of Rows (in Filtered list)
    By JTwrk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2012, 08:05 PM
  6. Copy and insert rows with contents and format based on specific number
    By fatalcore in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-13-2012, 03:38 AM
  7. Insert multiple rows in specific sections of sheet?
    By Marylander in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2007, 01:12 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