+ Reply to Thread
Results 1 to 8 of 8

insert blank rows every nth row and copy down data to fill blank rows

  1. #1
    Registered User
    Join Date
    10-03-2014
    Location
    Katy, TX
    MS-Off Ver
    2013
    Posts
    8

    insert blank rows every nth row and copy down data to fill blank rows

    Hi,

    I am working with a large spreadsheet with over 50000 rows containing data for 107 participants in a study observed 480 times. I originally had 476 observations, but now need to ad the four extra observations for each participant. There are some data that just need to be copied down from the previous information to fill the 4 new rows per participant (e.g., Vars 1-4 below). The other variables (e.g., Vars 20-22) change over time, so I will be entering them manually.

    Data format is as follows:

    Participant Time Var 1 Var 2 Var 3 Var 4 .....Var 20 Var 21 Var 22...
    1 1 a1 b1 c1 d1 x11 y11 z11
    1 2 a1 b1 c1 d1 x12 y12 z12
    1 3 a1 b1 c1 d1 x13 y13 z13
    1 4 a1 b1 c1 d1 x14 y14 z14
    2 1 a2 b2 c2 d2 x21 y21 z21
    2 2 a2 b2 c2 d2 x22 y22 z22
    2 3 a2 b2 c2 d2 x23 y23 z23
    2 4 a2 b2 c2 d2 x24 y24 z24

    So, my task is as follows:

    1. For each participant number listed in column 1, insert 4 blank rows at the end. Skip down 476 rows and insert 4 more blank rows, and so on.
    2. Copy down variables that are common (Vars 1-4 in the example above) into the blank rows for each participant.


    Could anyone help me with the script for this?

    Thanks

    SR

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: insert blank rows every nth row and copy down data to fill blank rows

    Hi,

    Could you add a specific worked example showing a before and after situation. I'm not clear where the 4 new rows should be inserted. By 'at the end' do you mean at the change from say 1 to 2 or at the very bottom.

    You may not of course need a macro at all but a worked example will enable us to decide on an optimum solution. Is it a one off exercise since this often means using standard Excel functionality will be quicker than creating and testing a macro.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    10-03-2014
    Location
    Katy, TX
    MS-Off Ver
    2013
    Posts
    8

    Re: insert blank rows every nth row and copy down data to fill blank rows

    Thanks, and sorry for not being clear. The 4 news rows need to be added at the change from 1 to 2, and again from the change from 2 to 3, and so on. So, row 476 for participant 1 contains some data that I need to be copied to the four new rows for participant 1. Similarly, I need the data from the 476th row for participant 2 to be copied into the four new rows for that participant, and so on.
    I am attaching an excel example sheet with data for the first two participants before and after.

    Cheers

    Suresh
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: insert blank rows every nth row and copy down data to fill blank rows

    Try this. First test it on a copy of your data.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 10-06-2014 at 12:45 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Registered User
    Join Date
    10-03-2014
    Location
    Katy, TX
    MS-Off Ver
    2013
    Posts
    8

    Re: insert blank rows every nth row and copy down data to fill blank rows

    Quote Originally Posted by AlphaFrog View Post
    Try this. First test it on a copy of your data.

    Please Login or Register  to view this content.
    Thanks! I tried it on a sample dataset, but it worked only for the first unique participant. It did not insert and copy for the next one. Your help would be greatly appreciated!

  6. #6
    Registered User
    Join Date
    10-03-2014
    Location
    Katy, TX
    MS-Off Ver
    2013
    Posts
    8

    Re: insert blank rows every nth row and copy down data to fill blank rows

    Correction. It worked for all participants except the last one. I think I will take care of that manually! Thanks again for your help, alphafrog

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: insert blank rows every nth row and copy down data to fill blank rows

    Quote Originally Posted by surpass View Post
    Correction. It worked for all participants except the last one. I think I will take care of that manually! Thanks again for your help, alphafrog
    You're welcome.

    This does the last one.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-03-2014
    Location
    Katy, TX
    MS-Off Ver
    2013
    Posts
    8

    Re: insert blank rows every nth row and copy down data to fill blank rows

    perfect! Worked like a charm Thanks again!

+ 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. Replies: 4
    Last Post: 09-16-2014, 10:48 AM
  2. How to create a macro to insert blank rows and copy data into blank rows?
    By zodiack101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2013, 01:18 PM
  3. Copy up to blank cell, transpose, and insert rows without overwriting data below
    By scooter7 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-10-2013, 10:48 PM
  4. [SOLVED] Macro to insert blank rows so that the total number of rows with data is equal to 1021
    By nsm1411 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-07-2013, 10:25 AM
  5. macro copy fill the in-between blank rows
    By foxxkat in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-12-2005, 05:53 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