Adds a PivotTotal object to the PivotTotals collection.
expression.InsertTotal(Total, Before)
expression An expression that returns a PivotDataAxis object.
Total Required PivotTotal object. Specifies the total to be inserted.
Before Optional Variant. Specifies the index of the total before which the inserted total will be placed. If you do not specify this argument, the total is inserted at the end of the collection.
Remarks
If the PivotTotal object is currently part of the PivotTotals collection, the object is first removed from that collection and then reinserted into it. This changes the display order because totals are displayed in their collection order.
Example
This example adds a total named "Total Budget" that sums the values in the Budget field to PivotTable1, then then inserts the total into the PivotTable view.
Sub Add_Total()
Dim vwView
Dim ptConstants
Dim totNewTotal
Set vwView = PivotTable1.ActiveView
Set ptConstants = PivotTable1.Constants
' Add a new total named "Total Budget" to the current view.
Set totNewTotal = vwView.AddTotal("Total Budget", vwView.Fieldsets("budget").Fields(0), _
ptConstants.plFunctionSum)
' Insert the newly created total into the detail area of the PivotTable.
vwView.DataAxis.InsertTotal totNewTotal
End Sub