NamedRange.Subtotal Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates subtotals for the NamedRange control.
public object Subtotal (int GroupBy, Microsoft.Office.Interop.Excel.XlConsolidationFunction Function, object TotalList, object Replace, object PageBreaks, Microsoft.Office.Interop.Excel.XlSummaryRow SummaryBelowData = Microsoft.Office.Interop.Excel.XlSummaryRow.xlSummaryBelow);
abstract member Subtotal : int * Microsoft.Office.Interop.Excel.XlConsolidationFunction * obj * obj * obj * Microsoft.Office.Interop.Excel.XlSummaryRow -> obj
Public Function Subtotal (GroupBy As Integer, Function As XlConsolidationFunction, TotalList As Object, Optional Replace As Object, Optional PageBreaks As Object, Optional SummaryBelowData As XlSummaryRow = Microsoft.Office.Interop.Excel.XlSummaryRow.xlSummaryBelow) As Object
Parameters
- GroupBy
- Int32
The field to group by, as a one-based integer offset.
- Function
- XlConsolidationFunction
The subtotal function.Can be one of the following XlConsolidationFunction values: xlAveragexlCountxlCountNumsxlMaxxlMinxlProductxlStDevxlStDevPxlSumxlUnknownxlVarxlVarP
- TotalList
- Object
An array of 1-based field offsets, indicating the fields to which the subtotals are added.
- Replace
- Object
true
to replace existing subtotals. The default value is false
.
- PageBreaks
- Object
true
to add page breaks after each group. The default value is false
.
- SummaryBelowData
- XlSummaryRow
Places the summary data relative to the subtotal.Can be one of the following XlSummaryRow values: xlSummaryAbovexlSummaryBelow (default)
Returns
Examples
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);
}
Private Sub CreateSubtotal()
Me.Range("A1").Value2 = "Row 1"
Me.Range("B1").Value2 = "Row 2"
Me.Range("C1").Value2 = "Row 3"
Me.Range("A2", "A5").Value2 = 10
Me.Range("B2", "B5").Value2 = 20
Me.Range("C2", "C5").Value2 = 30
Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
= Me.Controls.AddNamedRange(Me.Range("A1", "C5"), _
"namedRange1")
Dim fields() As Integer = {1, 2, 3}
namedRange1.Subtotal(1, Excel.XlConsolidationFunction.xlSum, _
fields, , , Excel.XlSummaryRow.xlSummaryBelow)
End Sub
Remarks
Optional Parameters
For information on optional parameters, see Optional Parameters in Office Solutions.