Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Insert lines when x< y

I have a column of numbers as below:

1
1
1
2
2
2
3
3
........

I am writing a macro to insert lines between each didtinct number,
the code below isnt quite working - I am missing 1/2 lines somewhere,
thks in advance

Sub li()

Dim i
For i = 1 To 10
If Cells(i + 1, 5).Value < Cells(i, 5).Value Then
Cells(i + 1, 5).EntireRow.Insert
End If
Next


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Insert lines when x< y

If your numbers are in Column E then:

Sub li()
Dim LastRow As Long
Dim i As Long
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = LastRow - 1 To 1 Step -1
If Cells(i + 1, 5).Value < Cells(i, 5).Value Then
Cells(i + 1, 5).EntireRow.Insert
End If
Next
End Sub



--
Regards,
Tom Ogilvy




"teresa" wrote in message
...
I have a column of numbers as below:

1
1
1
2
2
2
3
3
.......

I am writing a macro to insert lines between each didtinct number,
the code below isnt quite working - I am missing 1/2 lines somewhere,
thks in advance

Sub li()

Dim i
For i = 1 To 10
If Cells(i + 1, 5).Value < Cells(i, 5).Value Then
Cells(i + 1, 5).EntireRow.Insert
End If
Next


End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Insert lines when x< y

correction:

Sub li()
Dim LastRow As Long
Dim i As Long
LastRow = Cells(Rows.Count, 5).End(xlUp).Row
For i = LastRow - 1 To 1 Step -1
If Cells(i + 1, 5).Value < Cells(i, 5).Value Then
Cells(i + 1, 5).EntireRow.Insert
End If
Next
End Sub

Changed the LastRow line to look in column 5 as well.

--
Regards,
Tom Ogilvy


"teresa" wrote in message
...
I have a column of numbers as below:

1
1
1
2
2
2
3
3
.......

I am writing a macro to insert lines between each didtinct number,
the code below isnt quite working - I am missing 1/2 lines somewhere,
thks in advance

Sub li()

Dim i
For i = 1 To 10
If Cells(i + 1, 5).Value < Cells(i, 5).Value Then
Cells(i + 1, 5).EntireRow.Insert
End If
Next


End Sub



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
Insert Lines RENEE Excel Worksheet Functions 7 May 7th 10 07:59 PM
Insert lines at each change in value LisaVH Excel Discussion (Misc queries) 3 December 13th 06 04:04 PM
how can i insert a row every five lines in excel Yogibear Excel Discussion (Misc queries) 1 August 3rd 06 08:06 PM
insert lines abunge Excel Discussion (Misc queries) 3 June 5th 06 09:02 AM
how to automatically insert blank lines in between non-blank lines No Name Excel Programming 2 November 17th 03 03:40 PM


All times are GMT +1. The time now is 05:21 PM.

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"