This documentation is archived and is not being maintained.

Range.Subtotal Method

Office 2007
Creates subtotals for the range (or the current region, if the range is a single cell).


expression.Subtotal(GroupBy, Function, TotalList, Replace, PageBreaks, SummaryBelowData)

expression   A variable that represents a Range object.


NameRequired/OptionalData TypeDescription
GroupByRequiredLongThe field to group by, as a one-based integer offset. For more information, see the example.
FunctionRequiredXlConsolidationFunction. The subtotal function.
TotalListRequiredVariantAn array of 1-based field offsets, indicating the fields to which the subtotals are added. For more information, see the example.
ReplaceOptionalVariantTrue to replace existing subtotals. The default value is True.
PageBreaksOptionalVariantTrue to add page breaks after each group. The default value is False.
SummaryBelowDataOptionalXlSummaryRow. Places the summary data relative to the subtotal.

Return Value


This example creates subtotals for the selection on Sheet1. The subtotals are sums grouped by each change in field one, with the subtotals added to fields two and three.

Visual Basic for Applications
Selection.Subtotal GroupBy:=1, Function:=xlSum, _
    TotalList:=Array(2, 3)