Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting the same text in various cells Josh W Excel Discussion (Misc queries) 4 April 24th 08 12:12 PM
Macro - Inserting text to a cell already containg text Dileep Chandran Excel Worksheet Functions 5 December 7th 06 03:42 PM
Macro - Inserting text to a cell already containg text Dileep Chandran Excel Discussion (Misc queries) 6 December 7th 06 03:42 PM
Inserting text from a cell in another tab Karen Smith Excel Discussion (Misc queries) 2 October 4th 06 06:16 PM
inserting text Jon1205 Excel Discussion (Misc queries) 6 July 28th 05 12:24 AM


All times are GMT +1. The time now is 03:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"