+ Reply to Thread
Results 1 to 8 of 8

Copy rows based on cell value, with loop

  1. #1
    Registered User
    Join Date
    08-16-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    88

    Copy rows based on cell value, with loop

    Hi,

    I have some sample data where columns F & G hold Start Date & End Date, eg, 11/01/2021 in column F and 13/11/2021 in column G.
    Taking those dates, I'd need the entire row to be duplicated until the start date is the same as the end date. So I'd end up with 3 rows of data with everything the same, except the start and end date.

    This is how the data starts:
    excel1.JPG

    The result would be like this (ignore the colours, they are there to try and make it appear more simple as to what is happening)
    ezcdl2.JPG

    So in the above, the yellow row has been duplicated 3 times as the start date (11/01/2021) and end date (13/11/2021) difference is three full days. On the newly created rows, both the start and end date show the individual date.

    I've also attached the sample file if that helps.

    Any ideas would be greatly appricated. I know I need a loop or two to cycle through the original list, and subtract the start date from the end date to get the duration, but after that I'm not sure how to duplicate the row X number of times and then change the start and end date.

    Huge thanks :D
    Attached Files Attached Files

  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: Copy rows based on cell value, with loop

    Presumably you'd expect Trainer 2 for DC2 to result in 31 rows. Your example assumes G6 is 28/01/21, it actually says 28/02/2021
    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
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Copy rows based on cell value, with loop

    Try this:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-16-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    88

    Re: Copy rows based on cell value, with loop

    Ahh, apologies, yep I meant 28/01/2021 - 28/01/2021

  5. #5
    Registered User
    Join Date
    08-16-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    88

    Re: Copy rows based on cell value, with loop

    Quote Originally Posted by Akuini View Post
    Try this:

    Please Login or Register  to view this content.


    Oooh that works perfectly, thanks for your help! :D

  6. #6
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Copy rows based on cell value, with loop

    You're welcome, glad to help & thanks for the feedback.

  7. #7
    Registered User
    Join Date
    08-16-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    88

    Re: Copy rows based on cell value, with loop

    Quote Originally Posted by Akuini View Post
    You're welcome, glad to help & thanks for the feedback.
    Hi again, sorry to be a pain but if you have a minute spare could you please explain what/how the code is working. I'm trying to understand it so I can better my own skills but struggling to follow what it's doing
    Thanks again and no worries if you don't have time to explain

  8. #8
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Copy rows based on cell value, with loop

    Sorry, it's hard for me to explain it in writing, harder than writing the code...

+ 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. Get rows in a loop from an another workbook based on certain a cell value
    By std51 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-13-2016, 03:56 PM
  2. [SOLVED] Copy cell value based on 2 Criteria with loop in to another worksheet
    By Ganeshgopinath in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2016, 11:06 AM
  3. [SOLVED] Loop through every second row and hide rows based on cell values
    By rtcwlomax in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-08-2016, 05:13 PM
  4. Copy 1 cell formula to a range of cells and loop every 3 rows
    By ArtPur in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-02-2013, 09:54 AM
  5. Delete Rows Based On Cell Value (Without For-Next Loop)
    By dkcel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2013, 11:48 PM
  6. Cut and Paste Rows based on Value in Cell Loop
    By mburke05 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-19-2012, 06:51 PM
  7. Need to loop through rows and copy values based on criteria
    By Nice in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2005, 08:49 AM

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