Skip to main content

Range.Subtotal method

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.


Name Required/Optional Data type Description
GroupBy Required Long The field to group by, as a one-based integer offset. For more information, see the example.
Function Required XlConsolidationFunction The subtotal function.
TotalList Required Variant An array of 1-based field offsets, indicating the fields to which the subtotals are added. For more information, see the example.
Replace Optional Variant True to replace existing subtotals. The default value is True.
PageBreaks Optional Variant True to add page breaks after each group. The default value is False.
SummaryBelowData Optional XlSummaryRow 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.

Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(2, 3)

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>