ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to add row (https://www.excelbanter.com/excel-discussion-misc-queries/124034-macro-add-row.html)

nazzoli

Macro to add row
 
I have a file that I will open on a weekly basis. I want it to create a
macro that will insert a blank row in between all rows. The number of rows
will vary weekly. Please help.


John Bundy

Macro to add row
 
This should do you

Sub main()
Dim myRow As Long
Dim lastCell As Long
myRow = 1 'first row to start on
lastCell = Cells(Rows.Count, "A").End(xlUp).Row

For i = lastCell To myRow Step -1
Cells(i, 1).Select
Selection.EntireRow.Insert Shift:=xlDown
Next

End Sub


--
--
-John
Please rate when your question is answered to help us and others know what
is helpful.

"nazzoli" wrote in message
...
I have a file that I will open on a weekly basis. I want it to create a
macro that will insert a blank row in between all rows. The number of
rows
will vary weekly. Please help.




nazzoli

Macro to add row
 
Thanks works great

"John Bundy" wrote:

This should do you

Sub main()
Dim myRow As Long
Dim lastCell As Long
myRow = 1 'first row to start on
lastCell = Cells(Rows.Count, "A").End(xlUp).Row

For i = lastCell To myRow Step -1
Cells(i, 1).Select
Selection.EntireRow.Insert Shift:=xlDown
Next

End Sub


--
--
-John
Please rate when your question is answered to help us and others know what
is helpful.

"nazzoli" wrote in message
...
I have a file that I will open on a weekly basis. I want it to create a
macro that will insert a blank row in between all rows. The number of
rows
will vary weekly. Please help.





Bob Phillips

Macro to add row
 
No need to select, inefficient and wasteful


Sub main()
Dim myRow As Long
Dim lastCell As Long
Dim i As Long
myRow = 1 'first row to start on
lastCell = Cells(Rows.Count, "A").End(xlUp).Row

For i = lastCell To myRow Step -1
Rows(i + 1).Insert
Next

End Sub



--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"John Bundy" wrote in message
...
This should do you

Sub main()
Dim myRow As Long
Dim lastCell As Long
myRow = 1 'first row to start on
lastCell = Cells(Rows.Count, "A").End(xlUp).Row

For i = lastCell To myRow Step -1
Cells(i, 1).Select
Selection.EntireRow.Insert Shift:=xlDown
Next

End Sub


--
--
-John
Please rate when your question is answered to help us and others know what
is helpful.

"nazzoli" wrote in message
...
I have a file that I will open on a weekly basis. I want it to create a
macro that will insert a blank row in between all rows. The number of
rows
will vary weekly. Please help.







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

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