jcb0806 0 Newbie Poster

I need help with code to find the sum of several different subtotals that may vary in the amount of data.

I have to pull from columns that may vary from report to report (the heading will always be the same but the columns may be different lengths)

Ex:
Category BankTotal MarketTotal
BSM 9 6
BSM 1 3
subtotal 10 9

PHM 1 2
PHM 1 2
PHM 1 2
subtotal 3 6

grand total 13 15


BSM might sometimes have 4 or 5 rows of data sometimes.
Just need for the " grand total" to always add the subtotal even if there is a change.

Can anybody help please?

Here is the code I have to give me the subtotals and spaces.

Dim Lastrow As Long
Dim FirstRow As Long
Dim i As Long
    With ActiveSheet
        Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
        For i = Lastrow To 2 Step -1
            FirstRow = i

            Do Until .Cells(FirstRow - 1, "A").Value <> .Cells(i, "A").Value
                FirstRow = FirstRow - 1

            Loop
            .Rows(i + 1).Resize(2).Insert
            .Cells(i + 1, "A").Value = "Sub Total"
            .Cells(i + 1, "E").Resize(, 3).Formula = "=SUM(E" & FirstRow & ":E" & i & ")"
     i = FirstRow
        Next i
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.