Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Inserting the same text in various cells | Excel Discussion (Misc queries) | |||
Macro - Inserting text to a cell already containg text | Excel Worksheet Functions | |||
Macro - Inserting text to a cell already containg text | Excel Discussion (Misc queries) | |||
Inserting text from a cell in another tab | Excel Discussion (Misc queries) | |||
inserting text | Excel Discussion (Misc queries) |