ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how can i create a macro that insert 2 rows (https://www.excelbanter.com/excel-programming/374231-how-can-i-create-macro-insert-2-rows.html)

andresg1975

how can i create a macro that insert 2 rows
 
how can i create a macro that selects, lets say column h, inserts two rows
every two rows.

column h

row 6 254
row 7 -254
row 8 450
row 9 -450

final result should be:

column h

row 6 254
row 7 -254
inserted row
inserted row
row 8 450
row 9 -450
inserted row
inserted row

and so on,

thanks a lot for your help

Bob Phillips

how can i create a macro that insert 2 rows
 
Sub Test()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
iLastRow = iLastRow - (iLastRow Mod 2 = 0)
For i = iLastRow To 2 Step -2
Rows(i).Resize(2).Insert
Next i

End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"andresg1975" wrote in message
...
how can i create a macro that selects, lets say column h, inserts two rows
every two rows.

column h

row 6 254
row 7 -254
row 8 450
row 9 -450

final result should be:

column h

row 6 254
row 7 -254
inserted row
inserted row
row 8 450
row 9 -450
inserted row
inserted row

and so on,

thanks a lot for your help





All times are GMT +1. The time now is 02:08 PM.

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