C
Chad
Hi
I have been working on inserting a line whenever the cost centre
changes, then summing the next 10 columns to the right. I have found
some code which inserts a row and sums the like totals of only one
column. Can someone help with extending it out 10 columns. I don't
want to use the subtotal function for a range of reasons. Ta
eg
AA 2 5
AA 2 4
Total 4 9
BB 4 6
BB 4 3
Total 8 9
Regards
Chad
Sub sumrow()
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
I have been working on inserting a line whenever the cost centre
changes, then summing the next 10 columns to the right. I have found
some code which inserts a row and sums the like totals of only one
column. Can someone help with extending it out 10 columns. I don't
want to use the subtotal function for a range of reasons. Ta
eg
AA 2 5
AA 2 4
Total 4 9
BB 4 6
BB 4 3
Total 8 9
Regards
Chad
Sub sumrow()
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