Expand Minimize

NamedRange.Subtotal Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Creates subtotals for the NamedRange control.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Object Subtotal(
	int GroupBy,
	XlConsolidationFunction Function,
	Object TotalList,
	Object Replace,
	Object PageBreaks,
	XlSummaryRow SummaryBelowData
)

Parameters

GroupBy
Type: System.Int32

The field to group by, as a one-based integer offset.

Function
Type: Microsoft.Office.Interop.Excel.XlConsolidationFunction

The subtotal function.

Can be one of the following XlConsolidationFunction values:

xlAverage

xlCount

xlCountNums

xlMax

xlMin

xlProduct

xlStDev

xlStDevP

xlSum

xlUnknown

xlVar

xlVarP

TotalList
Type: System.Object

An array of 1-based field offsets, indicating the fields to which the subtotals are added.

Replace
Type: System.Object

true to replace existing subtotals. The default value is false.

PageBreaks
Type: System.Object

true to add page breaks after each group. The default value is false.

SummaryBelowData
Type: Microsoft.Office.Interop.Excel.XlSummaryRow

Places the summary data relative to the subtotal.

Can be one of the following XlSummaryRow values:

xlSummaryAbove

xlSummaryBelow (default)

Return Value

Type: System.Object

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example creates subtotals for a NamedRange. The subtotals are the sum of all three fields in the NamedRange.

This example is for a document-level customization.

private void CreateSubtotal()
{
    this.Range["A1"].Value2 = "Row 1";
    this.Range["B1"].Value2 = "Row 2";
    this.Range["C1"].Value2 = "Row 3";

    this.Range["A2", "A5"].Value2 = 10;
    this.Range["B2", "B5"].Value2 = 20;
    this.Range["C2", "C5"].Value2 = 30;

    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "C5"],
        "namedRange1");

    int[] fields = new int[] { 1, 2, 3 };
    namedRange1.Subtotal(1, Excel.XlConsolidationFunction.xlSum,
        fields, Excel.XlSummaryRow.xlSummaryBelow);
}

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft