Creating a Worksheet Subtotal via code:   Return to List

Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(3, 5), _
    Replace:=False, PageBreaks:=False, SummaryBelowData:=True

' In the above function:

GroupBy:=1' means that when the first column changes, subtotals are generated
Function:=xlSum' the type of subtotal performed (generally a summation)
TotalList:=Array(3, 5),' the columns which are subtotalled
Replace:=False' if this were true -- a prior subtotal would be replaced
PageBreaks:=False' if this were true -- there would be a page break generated at each subtotal line
SummaryBelowData:=True' means that a grandtotal row will be placed beneath all subtotals



Note to Webmaster