Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Line insertion

Hi,

Can anyone tell me how I use VBA to compare rows to each
other and if the previous row is different to the current
row then insert a line and sum the total of the row that
are equal?
This is really driving me mad. I have tried using the
Sumtotals option in the data menu in excel but I want to
compare rows using two or more cells in a row. ie coparing
by column b then by coulmn a and summing column c.

Can this be done is VBA?
Any help would be great thanks

Andy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Line insertion

Sub Tester2()
Dim Start As Range, Cell As Range
Set Start = Range("C1")
Set Cell = Range("B2")
Do While Not IsEmpty(Cell)
If Cell.Value < Cell(0).Value Or _
Cell(1, 0).Value < Cell(0, 0).Value Then
Cell.EntireRow.Insert
Cell(0, 2).Formula = "=sum(" & _
Range(Start, Cell(-1, 2)).Address & ")"
Set Start = Cell(1, 2)
End If
Set Cell = Cell(2, 1)
Loop
Cell(1, 2).Formula = "=sum(" & _
Range(Start, Cell(0, 2)).Address & ")"

End Sub

--
Regards,
Tom Ogilvy


"Andy" wrote in message
...
Hi,

Can anyone tell me how I use VBA to compare rows to each
other and if the previous row is different to the current
row then insert a line and sum the total of the row that
are equal?
This is really driving me mad. I have tried using the
Sumtotals option in the data menu in excel but I want to
compare rows using two or more cells in a row. ie coparing
by column b then by coulmn a and summing column c.

Can this be done is VBA?
Any help would be great thanks

Andy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Line insertion


Thanks for the help.




-----Original Message-----
Sub Tester2()
Dim Start As Range, Cell As Range
Set Start = Range("C1")
Set Cell = Range("B2")
Do While Not IsEmpty(Cell)
If Cell.Value < Cell(0).Value Or _
Cell(1, 0).Value < Cell(0, 0).Value Then
Cell.EntireRow.Insert
Cell(0, 2).Formula = "=sum(" & _
Range(Start, Cell(-1, 2)).Address & ")"
Set Start = Cell(1, 2)
End If
Set Cell = Cell(2, 1)
Loop
Cell(1, 2).Formula = "=sum(" & _
Range(Start, Cell(0, 2)).Address & ")"

End Sub

--
Regards,
Tom Ogilvy


"Andy" wrote in

message
...
Hi,

Can anyone tell me how I use VBA to compare rows to each
other and if the previous row is different to the

current
row then insert a line and sum the total of the row that
are equal?
This is really driving me mad. I have tried using the
Sumtotals option in the data menu in excel but I want to
compare rows using two or more cells in a row. ie

coparing
by column b then by coulmn a and summing column c.

Can this be done is VBA?
Any help would be great thanks

Andy



.

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
Row Insertion mlockman Excel Discussion (Misc queries) 0 April 17th 09 03:33 PM
Rows Insertion b166er Excel Worksheet Functions 1 June 22nd 06 04:41 PM
Rows Insertion b166er Excel Discussion (Misc queries) 1 June 22nd 06 03:35 PM
Row insertion macro Jeff Excel Programming 2 November 13th 03 04:35 PM
VBA Code- Row Insertion Jeff Excel Programming 3 November 11th 03 09:48 PM


All times are GMT +1. The time now is 01:37 AM.

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

About Us

"It's about Microsoft Excel"