Excel - Repeat Last row into N number of times

[Closed]
Report
Posts
1
Registration date
Tuesday February 28, 2017
Status
Member
Last seen
February 28, 2017
-
Posts
2805
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
September 14, 2021
-
Hello,

Can anyone help me to repeat last row into N number of times into same sheet.

Sample Data Where N=5

Column-A Column-B
abc 111
AAA 222


Expected Output.

Column-A Column-B
abc 111
AAA 222
AAA 222
AAA 222
AAA 222
AAA 222
AAA 222

1 reply

Posts
2805
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
September 14, 2021
481
Hi Abu,

You didn't mentioned where the number N can be found, so I let Excel ask you.

Here is the code:
Sub RunMe()
Dim x, N As Integer
N = InputBox("How many times do you want to repeat the last row?:")
x = Range("A1").End(xlDown).Row

Do Until N = 0
    Rows(x).Copy Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
    N = N - 1
Loop
End Sub


Best regards,
Trowa