+ Reply to Thread
Results 1 to 6 of 6

Duplicate a row several times, append info, then repeat

Hybrid View

  1. #1
    Registered User
    Join Date
    07-22-2010
    Location
    Houston, TX
    MS-Off Ver
    Excel 2007
    Posts
    1

    Duplicate a row several times, append info, then repeat

    I don't know how complicated or simple this is, but I urgently need a macro that does the following for 372 rows.

    Copy one row, duplicate it (either into a new sheet or on the current sheet) so that there are now 4 instances of the row, then append different bits of text to the cell in the first column of each of these four rows (append "-43", "-6", "-8", and "-10" respectively).

    I know I probably did a horrible job of describing that, so I have attached an XLSX book. The "Beginning" sheet is a very condensed example of what I have now. The "End" sheet is what it would look like after the macro has been executed.

    Obviously, doing this manually to 372 rows would be very time consuming and I really need to have this done soon.

    Thank you very very much to whoever can help!

    Edit: I have also uploaded the example workbook as a XLS file.
    Attached Files Attached Files
    Last edited by artizhay; 07-22-2010 at 02:19 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Duplicate a row several times, append info, then repeat

    Try this:
    Option Explicit
    
    Sub TimesFourPLUS()
    Dim LR      As Long
    Dim Rw      As Long
    Dim Val     As String
    Application.ScreenUpdating = False
    
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
        For Rw = LR To 1 Step -1
            Rows(Rw).Copy
            Range("A" & Rw + 1).Resize(3).EntireRow.Insert
            Val = Range("A" & Rw)
            Range("A" & Rw) = Val & "-43"
            Range("A" & Rw + 1) = Val & "-8"
            Range("A" & Rw + 2) = Val & "-8"
            Range("A" & Rw + 3) = Val & "-10"
        Next Rw
    
    Application.ScreenUpdating = True
    Application.CutCopyMode = False
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-26-2010
    Location
    Davis, US
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Duplicate a row several times, append info, then repeat

    Hi, this problem is very similar to mine. However I am very ignorant on how to create macros (I assume that is what you have described) - could you please tell me where and how to enter this formula?

  4. #4
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Duplicate a row several times, append info, then repeat

    artizhay;

    Here's a file that does it for you.

    In the macro "Duplicate_And_Append", change the area between the '************** to fit your workbook.

    The macro puts the results 2 rows below the last row in column "A" of whatever sheet you set shSheetTo to. So when you open my file and just run "Duplicate_And_Append" you will see the results create a 3rd copy on Sheet3.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  5. #5
    Registered User
    Join Date
    10-26-2010
    Location
    Davis, US
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Duplicate a row several times, append info, then repeat

    Hi, this problem is very similar to mine. However I am very ignorant on how to create macros (I assume that is what you have described) - could you please tell me where and how to enter this formula?

    (My apologies foxguy I meant to post this to JBeaucaire)

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Duplicate a row several times, append info, then repeat

    This is the programming forum. Macros are installed into code modules in the VB editor, unlike formulas which are typed directly into cells.

    Please post a thread of your own with supporting documentation, outline your issue, add a sample workbook, etc. If you find other threads relevant to your issue, put a link to them in your new thread. Be sure to pick the correct forum, programming or general.

    Be sure to read through the Forum Rules so you can use and follow them effectively.

+ 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