I am using the following code:
The result is as follows:
48 960
126 2520
174 3480 Total
56 1680
230 5160 Total
500 10,000
730 15160 Total
The problem is the totals are adding up the above lines if there is only 1 item to be summed. It should only be summing the numbers until the blank space. I have looked at the code until I am blue in the face. Clearly I am missing something. If anyone can see the solution please let me know.
Thanks
Luke
Code:
Dim r As Long
For r = Cells(Rows.Count, "A").End(xlUp).Row To 3 Step -1
If Range("H" & r).Value <> Range("H" & r - 1) Then
Rows(r).Insert
Rows(r).Insert
End If
Next r
For r = 2 To Cells(Rows.Count, "A").End(xlUp).Row + 1
If IsEmpty(Range("a" & r).Value) Then
Range("A" & r).Value = "Total"
MY_END = Range("A" & r - 1).Row
MY_START = Range("A" & r - 1).End(xlUp).Row
If MY_START = 1 Then MY_START = 2
Range("F" & r).Formula = "=sum(F" & MY_START & ":F" & MY_END & ")"
Range("F" & r).Copy Range("G" & r)
r = r + 1
End If
Next r
The result is as follows:
48 960
126 2520
174 3480 Total
56 1680
230 5160 Total
500 10,000
730 15160 Total
The problem is the totals are adding up the above lines if there is only 1 item to be summed. It should only be summing the numbers until the blank space. I have looked at the code until I am blue in the face. Clearly I am missing something. If anyone can see the solution please let me know.
Thanks
Luke