Try the code as posted. I assume your item descriptions are in column 'A' and your costs are in column 'B'. What it does is to place an indirect sum into 'B' column adjacent to each 'SUB TOTAL' string it finds (typed that way ignoring case). I also assume the values start at row 1 which you'll probably not want it to do. I accumulate a sum string and place it in the row immediately after the last subtotal row I find. Each subtotal cell will be given a cyan color background and a top border. Presumably you'll be able to continue on from this point and modify it to suit your needs.
Function findSubTotalRows(lastRow As Integer) As Collection
Dim regEx As New RegExp
Dim subTotCols As Collection
regEx.Global = True
regEx.IgnoreCase = True
regEx.Pattern = "^SUB TOTAL$"
Dim row As Integer
Dim val As String
Set subTotCols = New Collection
For row = 1 To lastRow:
val = Trim(Cells(row, 1).Value)
Set mat = regEx.Execute(val)
If mat.Count = 1 Then
subTotCols.Add row
End If
Next
Set findSubTotalRows = subTotCols
End Function
Sub sum_up_subtotals()
Dim lastRow As Integer
Dim cols As Collection
' Find last row in column and all sub total rows
lastRow = Range("A1000").End(xlUp).row
Set cols = findSubTotalRows(lastRow)
Dim prevRow As Integer: prevRow = 0
Dim numRng As Integer
Dim totStr As String: totStr = "=SUM("
For row = 1 To cols.Count:
thisRow = cols(row)
numRng = thisRow - prevRow - 1
With Cells(thisRow, 2)
.Formula = "=SUM(INDIRECT(ADDRESS(ROW()-" & CStr(numRng) & ",COLUMN())&"":""&ADDRESS(ROW()-1,COLUMN())))"
.Interior.Color = vbCyan
.NumberFormat = "$#,##0.00"
.Borders(xlEdgeTop).LineStyle = xlContinuous
End With
prevRow = thisRow
totStr = totStr & "B" & thisRow & ","
Next
totStr = Mid(totStr, 1, Len(totStr) - 1) & ")"
Cells(thisRow + 1, 2).value = totStr
End Sub
The nice thing about doing it this way is that you can insert additional rows into each of the subtotal segments or add new subtotal segments, run the macro and it should show the proper new sums.
It works for me but I just tried it with the data you provided. Note that you have to have regular expressions enabled for this to work.