Редагувати

Поділитися через


Range.Subtotal method (Excel)

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)

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.