+ Reply to Thread
Results 1 to 12 of 12

HELP!!! How to insert 170 empty rows at every 41th row?

  1. #1
    Registered User
    Join Date
    09-07-2020
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    6

    HELP!!! How to insert 170 empty rows at every 41th row?

    Hi all,

    How can I add 170 empty rows at every repeating 41th row for 40 sets? Was looking for a method to do that, only found methods to add one empty row at every 41th row, but I need to add 170 empty rows!

    Ultimately, I would want to integrate this method into a macro.

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    Welcome to the board

    Code below inserts 170 rows after row 40,80, etc
    If there are headers in row 1 and the data starts in row 2, amend Rows(1 + r * 40) to Rows(2 + r * 40)
    Please Login or Register  to view this content.
    Last edited by kev_; 09-07-2020 at 02:10 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    Check out this 1 minute video clip of me showing you how Excel can help you out a great deal with regard to what you want to do:

    https://drive.google.com/file/d/1Fh4...ew?usp=sharing

    now, you can take the code that Excel generates for you (which you see at the end of that video - I deleted most of it, and just kept the relevant 6 lines), combine it with a little more to loop your rows and count them accordingly, and boom, you're done!

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-07-2020
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    6

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    Quote Originally Posted by kev_ View Post
    Welcome to the board

    Code below inserts 170 rows after row 40,80, etc
    If there are headers in row 1 and the data starts in row 2, amend Rows(1 + r * 40) to Rows(2 + r * 40)
    Please Login or Register  to view this content.
    Sorry, I am a total noob to vba. How do you insert these code?

    Edit: i have figured how to get these to work. Thanks to all!
    Last edited by isaachoo; 09-07-2020 at 02:44 AM.

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    Quote Originally Posted by isaachoo View Post
    Sorry, I am a total noob to vba. How do you insert these code?
    (alt}{F11} is shortcut to go to VBA editor
    (see menu) Insert \ Module \ paste code into the open window
    (alt}{F11} is shortcut to go back to Excel

  6. #6
    Registered User
    Join Date
    09-07-2020
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    6

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    Thank you all again for the illuminating answer, I would like to close this thread since my query was answered. Admin pls help!

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    Quote Originally Posted by isaachoo View Post
    I would like to close this thread since my query was answered. Admin pls help!
    That is lazy
    Click on FAQ - it is the first item

  8. #8
    Registered User
    Join Date
    09-07-2020
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    6

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    As posted by kev_:

    Sub InsertRows()
    Dim r As Long
    For r = 40 To 1 Step -1
    Rows(1 + r * 40).Resize(170).Insert
    Next r
    End Sub

    May I know what each row and number means?

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    Sub InsertRows()
    Tell VBA to expect variable r to be an integer
    Dim r As Long
    Loop with values of r starting at 40 counting down to 1
    For r = 40 To 1 Step -1
    when r is 40 insert 170 rows at row 1601 [= 1 + (40 X 40)]
    When r is 39 insert 170 rows ar row 1561 [= 1 + (39 X 40)]
    etc ...

    Rows(1 + r * 40).Resize(170).Insert
    Next r
    End Sub

  10. #10
    Registered User
    Join Date
    09-07-2020
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    6

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    So if i put:
    For r = 1 to 40 Step +1
    It have similar effect?

  11. #11
    Registered User
    Join Date
    09-07-2020
    Location
    Singapore
    MS-Off Ver
    2016
    Posts
    6

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    Oh, i just realized that if i put R = 1 to 40, it does not work, as it will add 170 rows first to the 41th row, then everything will pushed down 1 row by 1 row.

    So adding rows from the bottom will not have such an issue. I hope my idea can be conveyed clearly...

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: HELP!!! How to insert 170 empty rows at every 41th row?

    The code on post#2 was written looping backwards to prevent that issue

+ 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] VBA to insert data in the first empty row (not last rows)
    By karimretina in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-05-2020, 05:04 PM
  2. Replies: 0
    Last Post: 09-18-2019, 05:41 AM
  3. [SOLVED] vba insert empty rows into worksheets
    By vio.coman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-17-2014, 07:25 AM
  4. [SOLVED] Insert empty/blank rows
    By Danielle22 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2013, 04:30 PM
  5. insert two empty rows below used data
    By johncena in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-01-2010, 05:49 AM
  6. insert 1 empty row after 100 rows
    By vinz20k in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-31-2007, 03:52 AM
  7. Macro To Insert Empty Rows??
    By rtidrtid in forum Excel General
    Replies: 1
    Last Post: 02-03-2006, 11:20 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