Excel - Repeat Last row into N number of times

Closed
Abu.hamna Posts 1 Registration date Tuesday February 28, 2017 Status Member Last seen February 28, 2017 - Feb 28, 2017 at 08:09 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Feb 28, 2017 at 11:48 AM
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
Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Feb 28, 2017 at 11:48 AM
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


0