ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   insert 2 rows and copy and paste (https://www.excelbanter.com/excel-programming/389668-insert-2-rows-copy-paste.html)

steveo[_2_]

insert 2 rows and copy and paste
 
I came across this macro to insert, copy and paste a row. Is there a
way to modify it to insert, copy and paste 2 rows?

Sub AddRows()
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 1 Step -1
Rows(i + 1).Insert
Rows(i + 1).FillDown
Next
End Sub


Dave Peterson

insert 2 rows and copy and paste
 
Maybe...

Option Explicit
Sub Add2Rows()
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 1 Step -1
Rows(i + 1).Resize(2).Insert
Rows(i).Resize(3).FillDown
Next i
End Sub



steveo wrote:

I came across this macro to insert, copy and paste a row. Is there a
way to modify it to insert, copy and paste 2 rows?

Sub AddRows()
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 1 Step -1
Rows(i + 1).Insert
Rows(i + 1).FillDown
Next
End Sub


--

Dave Peterson

steveo[_2_]

insert 2 rows and copy and paste
 
On May 18, 5:59 pm, Dave Peterson wrote:
Maybe...

Option Explicit
Sub Add2Rows()
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 1 Step -1
Rows(i + 1).Resize(2).Insert
Rows(i).Resize(3).FillDown
Next i
End Sub

steveowrote:

I came across this macro to insert, copy and paste a row. Is there a
way to modify it to insert, copy and paste 2 rows?


Sub AddRows()
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 1 Step -1
Rows(i + 1).Insert
Rows(i + 1).FillDown
Next
End Sub


--

Dave Peterson


Thank you Dave. This works well for me.



All times are GMT +1. The time now is 07:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com