close

Hi,
I need some help with a part of my macro.

I have a sheet like this
1 text1
1 text2...
1
2
2
3

I want my macro to find every change in the index (1,2,3,...) and then
insert two new rows beneath the last row with each index. I think I need some
kind of loop to locate the changes, and I can't find the right code for this.
Insertion of the rows are OK.

Thanks!

Here goes Traima, this will put in 2 blank rows at each change and terminate
when it hits the end of the list.

Sub row_insert()
' go to start point and select second cell in list
Worksheets(quot;sheet1quot;).Range(quot;a2quot;).Select
'begin loop and compare to one above
Do Until ActiveCell.Offset(1, 0) = quot;quot;
If ActiveCell lt;gt; ActiveCell.Offset(-1, 0) Then
ActiveCell.EntireRow.Insert
ActiveCell.EntireRow.Insert
'insert text here if you want
Activecell = quot;Break point for quot; amp; activecell.offset(-1,0)
'step over inserted rows
ActiveCell.Offset(2, 0).Select
End If
'move down a row
ActiveCell.Offset(1, 0).Select
Loop

HTH

Giz

quot;Traimaquot; wrote:

gt; Hi,
gt; I need some help with a part of my macro.
gt;
gt; I have a sheet like this
gt; 1 text1
gt; 1 text2...
gt; 1
gt; 2
gt; 2
gt; 3
gt;
gt; I want my macro to find every change in the index (1,2,3,...) and then
gt; insert two new rows beneath the last row with each index. I think I need some
gt; kind of loop to locate the changes, and I can't find the right code for this.
gt; Insertion of the rows are OK.
gt;
gt; Thanks!

This works out just fine!
Thanks again

Gizmo63 skrev:

gt; Here goes Traima, this will put in 2 blank rows at each change and terminate
gt; when it hits the end of the list.
gt;
gt; Sub row_insert()
gt; ' go to start point and select second cell in list
gt; Worksheets(quot;sheet1quot;).Range(quot;a2quot;).Select
gt; 'begin loop and compare to one above
gt; Do Until ActiveCell.Offset(1, 0) = quot;quot;
gt; If ActiveCell lt;gt; ActiveCell.Offset(-1, 0) Then
gt; ActiveCell.EntireRow.Insert
gt; ActiveCell.EntireRow.Insert
gt; 'insert text here if you want
gt; Activecell = quot;Break point for quot; amp; activecell.offset(-1,0)
gt; 'step over inserted rows
gt; ActiveCell.Offset(2, 0).Select
gt; End If
gt; 'move down a row
gt; ActiveCell.Offset(1, 0).Select
gt; Loop
gt;
gt; HTH
gt;
gt; Giz
gt;
gt; quot;Traimaquot; wrote:
gt;
gt; gt; Hi,
gt; gt; I need some help with a part of my macro.
gt; gt;
gt; gt; I have a sheet like this
gt; gt; 1 text1
gt; gt; 1 text2...
gt; gt; 1
gt; gt; 2
gt; gt; 2
gt; gt; 3
gt; gt;
gt; gt; I want my macro to find every change in the index (1,2,3,...) and then
gt; gt; insert two new rows beneath the last row with each index. I think I need some
gt; gt; kind of loop to locate the changes, and I can't find the right code for this.
gt; gt; Insertion of the rows are OK.
gt; gt;
gt; gt; Thanks!

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()