Skip to main content

How to copy and insert row multiple times or duplicate the row x times in Excel?

In your daily work, have you ever tried to copy a row or each row and then insert multiple times below the current data row in a worksheet? For example, I have a range of cells, now, I want to copy each row and paste them 3 times to the next row as following screenshot shown. How could you deal with this job in Excel?


Copy and insert a specific row multiple times with VBA code

If you want to duplicate only one specific row x times, the following VBA code may help you, please do as this:

1. Specify a row which you want to copy and insert multiple times, and then hold down the ALT + F11 keys, then it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Duplicate one specific row multiple times:

Sub test()
'Updateby Extendoffice
    Dim xCount As Integer
LableNumber:
    xCount = Application.InputBox("Number of Rows", "Kutools for Excel", , , , , , 1)
    If xCount < 1 Then
        MsgBox "the entered number of rows is error, please enter again", vbInformation, "Kutools for Excel"
        GoTo LableNumber
    End If
    ActiveCell.EntireRow.Copy
    Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(xCount, 0)).EntireRow.Insert Shift:=xlDown
    Application.CutCopyMode = False
End Sub

3. After pasting the code, please press F5 key to run this code, and a prompt box is popped out to remind you to enter the number of times that you want to duplicate, see screenshot:

4. Then click OK button, and three new copied rows have been inserted below the selected row, see screenshot:


Copy and insert each row multiple times based on a specific number easily

Normally, there is not a good method for copying and inserting rows multiple times except dealing with manually copy and insert. But, with Kutools for Excel's Duplicate Rows / columns based on cell value feature, you can solve this problem with ease. Click to download Kutools for Excel!

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


Copy and insert each row multiple times with VBA code

To duplicate each rows multiple times in a range, you can apply the following VBA code, please do as below:

1. Hold down the ALT + F11 keys, then it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Duplicate each row multiple times:

Sub insertrows()
'Updateby Extendoffice
Dim I As Long
Dim xCount As Integer
LableNumber:
xCount = Application.InputBox("Number of Rows", "Kutools for Excel", , , , , , 1)
If xCount < 1 Then
MsgBox "the entered number of rows is error ,please enter again", vbInformation, "Kutools for Excel"
GoTo LableNumber
End If
For I = Range("A" & Rows.CountLarge).End(xlUp).Row To 2 Step -1
Rows(I).Copy
Rows(I).Resize(xCount).Insert
Next
Application.CutCopyMode = False
End Sub

3. And then press F5 key to run this code, and a prompt box is popped out to remind you to enter the number of times that you want to duplicate for each record, see screenshot:

4. Then click OK, and each row has been copied and inserted 3 times below the active ones, see screenshot:

Note: In the above code, the A indicates the data range is started at column A, if your data starts at column K, please change A to K as your need.


Copy and insert each row multiple times based on a specific number with an awesome feature

Maybe, you are not familiar with the VBA code,or worry about the code will crash your data. Here, I will introduce a useful feature, Kutools for Excel's Duplicate Rows / Columns based on cell value, with this utility, you can quickly copy and insert the rows based on the number you specified.

Tips:To apply this Duplicate Rows / Columns based on cell value feature, firstly, you should download the Kutools for Excel, and then apply the feature quickly and easily.

After installing Kutools for Excel, please do as this:

1. Enter the repeat numbers that you want to duplicate rows in a list of cells beside your data, see screenshot:

2. Click Kutools > Insert > Duplicate Rows / Columns based on cell value, see screenshot:

3. In the Copy and insert rows & columns dialog box, select Copy and insert rows option in the Type section,  then select the data range you want to duplicate, and then specify the repeat time to duplicate the rows, see screenshot:

4. Then, click Ok or Apply button, you will get the following result as you need:

Click to Download Kutools for Excel and free trial Now!

Best Office Productivity Tools

Supercharge Your Spreadsheets: Experience Efficiency Like Never Before with Kutools for Excel

Popular Features: Find/Highlight/Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns     Move Columns   |   Unhide Columns   |   Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolset12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   Many More...

Kutools for Excel boasts over 300 features, ensuring that what you need is just a click away...

Supports Office/Excel 2007-2021 & newer, including 365   |   Available in 44 languages   |   Enjoy a full-featured 30-day free trial.

kte tab 201905


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (32)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Halo

Ik heb een zoek programma gemaakt met VBA die de cel van het gezocht item groen maakt
Bijv. saldo 1 euro komt 3x voor in een blad ( B2 t/m F16 )
Dan maakt hij 3x de cel Saldo 1 euro groen
Nou zou ik graag willen dat hij deze 3 items kopieert op hetzelfde blad in kolom H
Wie weet hoe je dit moet schrijven in een Macro

B.v.d. Michel
This comment was minimized by the moderator on the site
Bonjour,
J'ai pu tester ce code (celui en haut du post) pour dupliquer plusieurs lignes autant de fois que le nombre présent dans la dernière colonne. Cela fonctionne très bien, Merci.
Par contre, dans une des colonnes, il y a une date de début. Je voudrais que cette date s'incrémente automatiquement lors de la duplication.
Pouvez vous m'aider s'il vous plait, je ne trouve pas la réponse sur internet ?
Merci par avance.
This comment was minimized by the moderator on the site
It took more time to make google understand what I want, But after I found this page, it takes a few minutes to get what I was searching for. Many thanks 👍
This comment was minimized by the moderator on the site
I desire to have the VBA Code for Copy And Insert Each Row Multiple Times Based On A Specific Number , please assist, Thank you
This comment was minimized by the moderator on the site
Hi, Carl,To copy and insert the rows multiple times based on specific numbers, please apply the below code:<div data-tag="code">Sub CopyRow()
'UpdatebyExtendoffice
Dim xRg As Range
Dim xCRg As Range
Dim xFNum As Integer
Dim xRN As Integer
On Error Resume Next
SelectRange:
xTxt = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Select the list of numbers to copy the rows based on: ", "Kutools for Excel", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub

If xRg.Columns.Count > 1 Then
MsgBox "Please select single column!"
GoTo SelectRange
End If
Application.ScreenUpdating = False
For xFNum = xRg.Count To 1 Step -1
Set xCRg = xRg.Item(xFNum)
xRN = CInt(xCRg.Value)
With Rows(xCRg.Row)
.Copy
.Resize(xRN).Insert
End With
Next
Application.ScreenUpdating = True
End SubPlease try, hope it can help you!
This comment was minimized by the moderator on the site
skyyang not work!
This comment was minimized by the moderator on the site
This code works great. I have a situation where I am using Excel as a quote form. Worksheet one is the actual bid, and worksheet two is our cost page. When I insert the copied rows, I need it to do so on both pages. I have tried adding some code to select both pages, but it does not seem to work. Any help is greatly appreciated.
This comment was minimized by the moderator on the site
For the second VBA code (VBA code: Duplicate each row multiple times) I keep getting as run time error: 1004
This comment was minimized by the moderator on the site
Hello, is it possible to use different sizes(values) for each row? I am trying using vector, but it is not working.
For instance :
Rows(I).Resize(xCount(y) ).Insert

Where the values saved in xCount(y) are read from a table.
This comment was minimized by the moderator on the site
Hello, Guss,
May be the below article can help you, please check it:
https://www.extendoffice.com/documents/excel/4054-excel-duplicate-rows-based-on-cell-value.html
This comment was minimized by the moderator on the site
hi everyone.. Thank you in advance for you help!!

The VBA code to duplicate one specific row multiple times work perfectly until you use a filter. I wonder if someone can help me to solve this issue. I need a code that work even if you have some values filtered. I am using a large amount of data that is sort by locations. The code partially work, it pastes the number of row desire but no data or format when I have applied a filter.
This comment was minimized by the moderator on the site
No funciona con Windows 2019, deseo usar la función en mención pero simplemente no hace absolutamente nada
This comment was minimized by the moderator on the site
Copy And Insert Each Row Multiple Times With VBA Code

In VBA code how can I select the starting row
This comment was minimized by the moderator on the site
hi this worked great, only i need two rows copied N number of times. Can you please adjust the code so when i select two rows, it will then copy those two rows down N times ? thanks for your help
This comment was minimized by the moderator on the site
Hello, Sal,
If you need to only copy two rows down by multiple times, you just need to use the VBA code 1 in this article, apply the code two times will solve your problem. Please try, hope it can help you!
This comment was minimized by the moderator on the site
how to perform the same action with selected cells using VB,


I need to repeat a few selected cells (rows and columns) x no of times in the same sheet and in the same order as:

line1
line2
line3

line1
line2
line3
This comment was minimized by the moderator on the site
How can I do this for columns?
This comment was minimized by the moderator on the site
how do I do this for columns?
This comment was minimized by the moderator on the site
Love it! It works every time! Thank you so much for this :)
This comment was minimized by the moderator on the site
Hello, I need help, this is how my table looks, for example, when I add 2 row at the end of my 1st table, I want the vba help me to do the same thing for the table below (add 2 rows at the end of the table). So my job will be, only need to add rows at the 1st table, the table bellows all will generate rows automatically based on numbers of row in the 1st table. the are the coding I used now to add row for the 1st table. I hope someone can solve this issue for me, thx.Sub InsertNumRows()

ActiveCell.EntireRow.Copy

Dim Rng As Long

Application.DisplayAlerts = False
On Error Resume Next
Rng = InputBox("Enter number of rows required.")
On Error GoTo 0
Application.DisplayAlerts = True

If Rng = 0 Then
MsgBox "You didn't specify a range!"
Exit Sub

Else
Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(Rng, 0)).Select
Selection.EntireRow.Insert Shift:=xlDown
End If

End Sub
This comment was minimized by the moderator on the site
Love the code! how do i set the start range to skip the first row (Column Headers) and start on row 2?
This comment was minimized by the moderator on the site
Hi, Devin,
To skip the first header row, please apply the following VBA code:

Sub insertrows()
Dim I As Long
Dim xCount As Integer
LableNumber:
xCount = Application.InputBox("Number of Rows", "Kutools for Excel", , , , , , 1)
If xCount < 1 Then
MsgBox "the entered number of rows is error ,please enter again", vbInformation, "Kutools for Excel"
GoTo LableNumber
End If
For I = Range("A" & Rows.CountLarge).End(xlUp).Row To 2 Step -1
Rows(I).Copy
Rows(I).Resize(xCount).Insert
Next
Application.CutCopyMode = False
End Sub

Please try it, hope it can help you!
This comment was minimized by the moderator on the site
Really thanks for your support !!!!
This comment was minimized by the moderator on the site
Hi, how can I change the code to include the following

1. duplicate based on number of days
2. change column EOM from end of month to daily date
This comment was minimized by the moderator on the site
I used this macros in the past and it has always worked until lately. Any insight why it would only duplicate the top row even when using the multiple row macros? I have removed all filters/frozen panes.
This comment was minimized by the moderator on the site
I want to duplicate rows based on a parameter. For example, I have a column named meeting duration time. If that column is more than 1, I want to duplicate meeting ID rows based on that number. If meeting duration is 2 hours, then duplicate meetingID two times. If meeting is 3 hours then duplicate three times.
half an hour increments can be roundup to the hour.

MeetingID Time of Start Time of End Meeting Duration
43117 9:00 AM 11:00 AM 02:00
43580 9:30 AM 11:00 AM 01:30
42699 10:00 AM 11:30 AM 01:30
12345 01:00 PM 2:00 PM 01:00
This comment was minimized by the moderator on the site
I have the same problem. Have you found a solution?
This comment was minimized by the moderator on the site
Hi, guys,
May be the following VBA code can do you a favor, please apply it:
Sub insertrows()
Dim I As Long
Dim xRg As Range
Dim xHour, xMin As Long
On Error Resume Next
Application.ScreenUpdating = False
For I = Range("D" & Rows.CountLarge).End(xlUp).Row To 1 Step -1
xHour = 0
Set xRg = Range("D" & I)
xHour = Hour(xRg.Value) + 1
xMin = Minute(xRg.Value)
If xMin < 30 Then xHour = xHour - 1
Rows(I).Copy
Rows(I).Resize(xHour).Insert
Next
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub

Please try it. Hope it can help you!
This comment was minimized by the moderator on the site
i want to generate duplicate rows randomly,

for eg. generate random duplicate rows between 20 to 80.


what will be updated code for the following


Sub insertrows()
'Updateby Extendoffice 2016616
Dim I As Long
Dim xCount As Integer
LableNumber:
xCount = Application.InputBox("Number of Rows", "Kutools for Excel", , , , , , 1)
If xCount < 1 Then
MsgBox "the entered number of rows is error ,please enter again", vbInformation, "Kutools for Excel"
GoTo LableNumber
End If
For I = Range("A" & Rows.CountLarge).End(xlUp).Row To 1 Step -1
Rows(I).Copy
Rows(I).Resize(xCount).Insert
Next
Application.CutCopyMode = False
End Sub
This comment was minimized by the moderator on the site
real nice macro mate!
This comment was minimized by the moderator on the site
Awesome Macro - Saved me so much time!
This comment was minimized by the moderator on the site
Thank you!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations