Skip to main content

Range.Subtotal method

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

Syntax

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

expression A variable that represents a Range object.

Parameters

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

Variant

Example

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.

Worksheets("Sheet1").Activate
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>