ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to insert columns with macro (https://www.excelbanter.com/excel-programming/284065-how-insert-columns-macro.html)

THE GAME

How to insert columns with macro
 
I've got a spreadsheet that I need to modify. One of the fields says "number
of photos" and I want to take that number, and insert the number of rows I
want right beneath, then continue to the next item in the field and do the
same thing.

In the other columns, I want to copy the data that's there to the new
row(s).

I can't find a command to automatically insert a row, though.

Thanks in advance.



Trevor Shuttleworth

How to insert columns with macro
 
This will insert the rows for you.

Sub InsertRows()
Dim LastRow As Long
Dim i As Long
Application.ScreenUpdating = False
LastRow = Range("A65536").End(xlUp).Row
For i = LastRow To 1 Step -1
If IsNumeric(Range("A" & i)) Then
Range("A" & i).Offset(1, 0).Resize(Range("A" & i)).EntireRow.Insert
End If
Next 'i
Application.ScreenUpdating = True
End Sub

Regards

Trevor


"THE GAME" wrote in message
...
I've got a spreadsheet that I need to modify. One of the fields says

"number
of photos" and I want to take that number, and insert the number of rows I
want right beneath, then continue to the next item in the field and do the
same thing.

In the other columns, I want to copy the data that's there to the new
row(s).

I can't find a command to automatically insert a row, though.

Thanks in advance.





Tom Ogilvy

How to insert columns with macro
 
Numrows = 10
ActiveCell.Resize(numRows,1).EntireRow.Insert


--
Regards,
Tom Ogilvy


"THE GAME" wrote in message
...
I've got a spreadsheet that I need to modify. One of the fields says

"number
of photos" and I want to take that number, and insert the number of rows I
want right beneath, then continue to the next item in the field and do the
same thing.

In the other columns, I want to copy the data that's there to the new
row(s).

I can't find a command to automatically insert a row, though.

Thanks in advance.






All times are GMT +1. The time now is 02:16 AM.

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