#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Traima
 
Posts: n/a
Default Macro

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!
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gizmo63
 
Posts: n/a
Default Macro

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("sheet1").Range("a2").Select
'begin loop and compare to one above
Do Until ActiveCell.Offset(1, 0) = ""
If ActiveCell < ActiveCell.Offset(-1, 0) Then
ActiveCell.EntireRow.Insert
ActiveCell.EntireRow.Insert
'insert text here if you want
Activecell = "Break point for " & 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

"Traima" wrote:

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!

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Traima
 
Posts: n/a
Default Macro

This works out just fine!
Thanks again:)

Gizmo63 skrev:

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("sheet1").Range("a2").Select
'begin loop and compare to one above
Do Until ActiveCell.Offset(1, 0) = ""
If ActiveCell < ActiveCell.Offset(-1, 0) Then
ActiveCell.EntireRow.Insert
ActiveCell.EntireRow.Insert
'insert text here if you want
Activecell = "Break point for " & 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

"Traima" wrote:

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!

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
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
macro with F9 Kenny Excel Discussion (Misc queries) 1 August 3rd 05 02:41 PM
Make Alignment options under format cells available as shortcut dforrest Excel Discussion (Misc queries) 1 July 14th 05 10:58 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM


All times are GMT +1. The time now is 05:06 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"