Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Row Insertion | Excel Discussion (Misc queries) | |||
Rows Insertion | Excel Worksheet Functions | |||
Rows Insertion | Excel Discussion (Misc queries) | |||
Row insertion macro | Excel Programming | |||
VBA Code- Row Insertion | Excel Programming |