• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Duplicating multiple rows, multiple times at once

Scoady

New Member
Hi,

I am searching for a way in excel to duplicate multiple rows, multiple times, without having to copy and paste X amount of times.

More specifically, I have 64 rows of data, that I would like to duplicate below several times. The number of duplications vary, as I have several tabs with the same 64 rows, with a need to duplicate differing amounts, but for example if I needed to duplicate all those 64 rows 10 times, how could i do this?

I understand how to open VBA and insert a module, but i am not sure what the correct code would be.

Any help would be much appreciated. Thank you.
 
Hi,

I am searching for a way in excel to duplicate multiple rows, multiple times, without having to copy and paste X amount of times.

More specifically, I have 64 rows of data, that I would like to duplicate below several times. The number of duplications vary, as I have several tabs with the same 64 rows, with a need to duplicate differing amounts, but for example if I needed to duplicate all those 64 rows 10 times, how could i do this?

I understand how to open VBA and insert a module, but i am not sure what the correct code would be.

Any help would be much appreciated. Thank you.
Hello
Intresting question!
If you want to duplicate a block of rows multiple times in Excel using VBA, you can use a simple loop. Here's an example code that duplicates the first 64 rows ten times:

Check this code

>>> You've noted same thing yesterday <<<
>>> use code - tags <<<
Code:
Sub DuplicateRows()
    Dim i As Integer
    Dim j As Integer
    Dim totalDuplications As Integer
   
    ' Define the number of duplications
    totalDuplications = 10
   
    ' Loop through the specified number of duplications
    For j = 1 To totalDuplications
        ' Loop through the rows to be duplicated
        For i = 1 To 64
            ' Duplicate the entire row
            Rows(65 + (i - 1) + (j - 1) * 64).Insert Shift:=xlDown, CopyOrigin:=Rows(i)
        Next i
    Next j
End Sub
Am sure, you know how to execute. Here's how to use it:

1. Press `Alt + F11` to open the Visual Basic for Applications (VBA) editor.
2. Insert a new module: Right-click on any item in the Project Explorer, choose "Insert," and then "Module."
3. Copy and paste the provided code into the module.
4. Close the VBA editor.

Now, you can run this macro by pressing `Alt + F8`, selecting "DuplicateRows," and clicking "Run." Adjust the `totalDuplications` variable in the code to control how many times you want to duplicate the 64 rows.

Make sure to test this on a copy of your data before applying it to your actual workbook, as macros can't be undone with the regular "Undo" functionality in Excel.
 
Last edited by a moderator:
Back
Top