I think adding the sub-total uner each section makes it hard to read.
Normally people put the sub total in a new column to the right of the data.
I wrote the code both ways. You choose which you like best
Sub addsubtotal1()
'Put data in column F
RowCount = 2
StartRow = 2
Do While Cells(RowCount, "A") <> ""
If (Cells(RowCount, "B") <> _
Cells(RowCount + 1, "B")) Then
Cells(RowCount, "F").Formula = _
"=Sum(E" & StartRow & ":E" & _
RowCount & ")"
StartRow = RowCount + 1
End If
RowCount = RowCount + 1
Loop
End Sub
Sub addsubtotal2()
'Put data in new row
RowCount = 2
StartRow = 2
Do While Cells(RowCount, "A") <> ""
If (Cells(RowCount, "B") <> _
Cells(RowCount + 1, "B")) Then
Rows(RowCount + 1).Insert
Cells(RowCount + 1, "E").Formula = _
"=Sum(E" & StartRow & ":E" & _
RowCount & ")"
RowCount = RowCount + 2
StartRow = RowCount
Else
RowCount = RowCount + 1
End If
Loop
End Sub
"(E-Mail Removed)" wrote:
> Hi,
>
> The question I have is a follow-up to my previous question at URL,
> http://groups.google.com/group/micro...90e60d9327284e
>
> In case of url problem, the idea and objective is explained here:
> Case/Data/Background
> C5 = column 5, is a formula that calculate the total minutes (for the
> duration between C3 and C4), using Tom from Microsoft's formual of
> MOD(c4-c3,1)*24*60.
>
> C1(Date)C2(Task) C3(start) C4(end) C5(cal)
> 09/11 CF8 17:20 19:00 100
> 09/12 ink 21:30 23:00 90
> 9/14 CF8 15:20 18:30 190
> New Objective:
> Now, if I want to sort by C2 (column 2, Task)
> We'll get the following,
> C1(Date)C2(Task) C3(start) C4(end) C5(cal)
> 09/11 CF8 17:20 19:00 100
> 9/14 CF8 15:20 18:30 190
> 09/12 ink 21:30 23:00 90
> That's helpful but I'd like Excel to automatically insert a row right
> below each Task and does automatical subtotalling for the task, the
> desired state would look this:
> C1(Date)C2(Task) C3(start) C4(end) C5(cal)
> 9/11 CF8 17:20 19:00 100
> 9/14 CF8 15:20 18:30 190
> 290
> 9/12 ink 21:30 23:00 90
> 90
>
> How can I do that?
>
> Many thanks.
>
>