Excel: Add Subtotals After Each Data Break


Good morning, good afternoon and good evening to all, I can't seem to get this to insert a subtotal after each break I've created in my extract. It only installs a total after the first instance and not the others. Also, it only works in column H but I need it to install a total in column I as well.


' Add Subtotals
Dim ThisCell As Range
Dim MySum As Double
 
    Set ThisCell = Range("H2")
 
nxt:
 
    Do While ThisCell <> ""
        MySum = MySum + ThisCell
        Set ThisCell = ThisCell.Offset(1, 0)
    Loop
 
    ThisCell.Value = MySum
 
    If ThisCell.Offset(1, 0) <> "" Then
        Set ThisCell = ThisCell.Offset(1, 0)
        MySum = 0
        GoTo nxt
    End If
I have about five breaks currently but it could vary depending on the pulled data. Thanks in advance for your generous consideration. jski


This question generated 13 answers. To proceed to the answers, click here.

This thread is current as of April 27, 2015.


For more resources for Microsoft Excel