Help inserting row after text

T

timwell

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
 
A

Alan

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.
 
T

timwell

Thanks so much Alan. Works like a charm!
Timwell
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top