![]() |
Help inserting row after text
Hello,
I have a spreadsheet that I am trying to divide into sections with a macro. In column A, starting in cell A9 and going down, each section is divided by 4 dashes("----"). I would like the macro to find the "----" and then move down 2 rows and insert a row. This would divide the section and its subtotals from the next section of data. The data can contain up to 2000 rows. Thanks so much for any help. Timwell |
Help inserting row after text
Sub InsertRows()
Dim i As Integer Const LastRow As Integer = 2500 With ActiveSheet.Range("A1") For i = 1 To LastRow If .Offset(i, 0).Value = "----" Then .Offset(i + 2, 0).EntireRow.Insert End If Next i End With End Sub you can change the value of the constant to suit yourself but, without making the Sub fancy, the extra 500 allows for the rows that you insert. timwell wrote: Hello, I have a spreadsheet that I am trying to divide into sections with a macro. In column A, starting in cell A9 and going down, each section is divided by 4 dashes("----"). I would like the macro to find the "----" and then move down 2 rows and insert a row. This would divide the section and its subtotals from the next section of data. The data can contain up to 2000 rows. Thanks so much for any help. Timwell |
Help inserting row after text
Thanks so much Alan. Works like a charm!
Timwell Alan wrote: Sub InsertRows() Dim i As Integer Const LastRow As Integer = 2500 With ActiveSheet.Range("A1") For i = 1 To LastRow If .Offset(i, 0).Value = "----" Then .Offset(i + 2, 0).EntireRow.Insert End If Next i End With End Sub you can change the value of the constant to suit yourself but, without making the Sub fancy, the extra 500 allows for the rows that you insert. timwell wrote: Hello, I have a spreadsheet that I am trying to divide into sections with a macro. In column A, starting in cell A9 and going down, each section is divided by 4 dashes("----"). I would like the macro to find the "----" and then move down 2 rows and insert a row. This would divide the section and its subtotals from the next section of data. The data can contain up to 2000 rows. Thanks so much for any help. Timwell |
All times are GMT +1. The time now is 12:00 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com