+ Reply to Thread
Results 1 to 12 of 12

Conditionally insert a duplicate row

  1. #1
    Registered User
    Join Date
    06-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Conditionally insert a duplicate row

    I have a table with hundreds of rows but here's a basic example:
    __a___b_____c____
    1 Color Dates Completed (headings)
    2 red Date1 Yes
    3 red Date2 No
    4 blue Date3 Yes

    I need a formula/macro that will create a duplicate row underneath a row if the cell in column c says "Yes". If it's "No" or blank then do nothing. The duplicate row should copy everything exept in column c.
    Should look like this:
    __a___b_____c___
    1 Color Dates Completed (headings)
    2 red Date1 Yes
    3 red Date1
    4 red Date2 No
    5 blue Date3 Yes
    6 blue Date3

    Please help! Greatly appreciated
    Last edited by acohen12; 06-11-2013 at 03:34 PM.

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Conditionally insert a duplicate row

    HI acohen12,

    welcome to the forum.

    Try using below code:-

    Please Login or Register  to view this content.

    Regards,
    DILIPandey
    <click on below * if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Registered User
    Join Date
    06-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Conditionally insert a duplicate row

    Thank you DILIPandey. So far the conditional row insertion works. Also I need the cell contents to duplicate down to the next row (besides in column c), do you know how to do that?

    Appreciated,
    acohen12

  4. #4
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Conditionally insert a duplicate row

    Okay .. use below code:-

    Please Login or Register  to view this content.


    Regards,
    DILIPandey
    <click on below * if this helps>

  5. #5
    Registered User
    Join Date
    06-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Conditionally insert a duplicate row

    Thanks, so far so good!
    I need one final adjustment to it now. Since I continually add more rows of data to my table, I am wondering if you can add a shortcut key like "ctrl+y", that will only use your macro on the active row.
    Say here's a table:
    __a___b_____c____
    1 Color Dates Completed (headings)
    2 red Date1 Yes
    3 red Date1 No
    4 red Date2 No
    5 blue Date3 Yes (cell C5 is active)

    I would like to press ctrl+y, then use your macro only on the active row, not row 2 also.

    If you can do this, I would cherish you.
    Last edited by acohen12; 06-09-2013 at 12:01 PM.

  6. #6
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Conditionally insert a duplicate row

    Okay.. see the attached file.

    activerow checking.xlsm

    select any row and press ctrl + y and this will insert a row down if "yes" is there in column C in select row

    Regards,
    DILIPandey
    <click on below * if this helps>

  7. #7
    Registered User
    Join Date
    06-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Conditionally insert a duplicate row

    dilipandey,
    for some reason when I try it, it changes the data in column A to "Yes". It also only works for one of the rows, when I try it with another row, it doesn't work.

    What I want this macro to do is, like the second one you showed me:
    Sub DILIPandey()
    'copying row based on condition
    i = Range("a" & Rows.Count).End(xlUp).Row - 1
    Range("c2").Select
    For n = 1 To i
    If ActiveCell.Value = "Yes" Then
    ActiveCell.Offset(1, 0).EntireRow.Select
    Selection.EntireRow.Insert
    Selection.FillDown
    Selection.Range("c1:xfd1").Clear
    ActiveCell.Offset(1, 2).Select
    Else
    ActiveCell.Offset(1, 0).Select
    End If
    Next
    End Sub
    But only do this for the selected row that I would be inputing, not the entire worksheet at once.

    Thanks for your help.

  8. #8
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Conditionally insert a duplicate row

    Okay.. upload your workbook with this macro.



    Regards,
    DILIPandey
    <click on below * if this helps>

  9. #9
    Registered User
    Join Date
    06-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Conditionally insert a duplicate row

    My attachment shows what it should look like before and after the macro is used. Thanks for your effort.

    macro.xlsm

  10. #10
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Conditionally insert a duplicate row

    Okay.. your data was converted as Table, now corrected... try using below file:-

    change any value to "Yes" and press ctrl + y
    macro.xlsm


    Regards,
    DILIPandey
    <click on below * if this helps>

  11. #11
    Registered User
    Join Date
    06-08-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Conditionally insert a duplicate row

    Finally complete! Thank you for all of your help.
    -acohen12

  12. #12
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Conditionally insert a duplicate row

    You are welcome

    Please mark this thread as [SOLVED].. Thanks.


    Regards,
    DILIPandey
    <click on below * if this helps>

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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