Line insertion

A

Andy

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
 
T

Tom Ogilvy

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
 
A

andy

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





.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top