Sum of sub groups

A

AG

Hi,

I have data as described below:
AA1 BB1 CC1 10 EE1
AA2 BB2 CC2 8 EE2
AA3 BB3 CC3 4 EE3
AA4 BB4 CC4 5 EE4

AA5 BB5 CC5 10 EE5
AA6 BB6 CC6 20 EE6
AA7 BB7 CC7 5 EE3

So, basically I have subgroups like above in an spreadsheet. The
number of rows in each subgroup are not fixed. It may have any number
of rows. The only way I know is the subgroup is ended is when I
encounter a blank row. I need to insert a new row at the end of every
subgroup and then sum up column D in this newly inserted row. So, for
the group 1 I should have a sum of 27 (10+8+4+5), and for second sub
group my total should be 35 (10+20+5). Can someone suggest me how to
do this?

The number of subgroups will also be different in each spreadsheet.

Thanks in advance for the help.
 
D

Don Guillett

A macro solution

Option Explicit
Sub sumblocksonblank()
Dim i As Long
Dim ur As Long
For i = Cells(Rows.Count, "d"). _
End(xlUp).Row + 1 To 1 Step -1
If Len(Application.Trim(Cells(i, "d"))) < 1 Then
ur = Cells(i - 1, "d").End(xlUp).Row
Cells(i, "d").Formula = _
"=SUM(D" & ur & ":D" & i - 1 & ")"
'=SUM(D6:D8)
End If
Next i
End Sub
 

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