InsertFieldSet Method

Microsoft Office Web Components Visual Basic

Inserts a field set on the specified axis.

expression.InsertFieldSet(FieldSet, Before, Remove)

expression    An expression that returns a PivotAxis , PivotDataAxis , PivotFilterAxis , or PivotGroupAxis object.

FieldSet    Required PivotFieldSet object. Specifies the field set to be inserted.

Before    Optional Variant. Specifies the index of the field set before which the inserted field set will be placed.

Remove    Optional Boolean. This argument is reserved for future use, and its value is always True. When the field set is added to the specified axis, it is removed from any other axis.

Example

This example adds a fieldset to the row axis, data axis, and filter axis of PivotTable1.

Sub Add_Fields_To_PivotTable()
    Dim vwView
    Dim ptConstants
    Dim totOrderCount
    
    Set ptConstants = PivotTable1.Constants
    Set vwView = PivotTable1.ActiveView
    
    ' Add the ShipCountry field to the row axis.
    vwView.RowAxis.InsertFieldSet vwView.FieldSets("ShipCountry")
    
    ' Add the OrderId field to the data axis.
    vwView.DataAxis.InsertFieldSet vwView.FieldSets("OrderID")
    
    ' Add the ShipVia field to the filter axis
    vwView.FilterAxis.InsertFieldSet vwView.FieldSets("ShipVia")
    
    ' Create a total named "Order Count" that counts the OrderID field.
    Set totOrderCount = vwView.AddTotal("Order Count", vwView.FieldSets("OrderId").Fields("OrderId"), _
                        ptConstants.plFunctionCount)
    
    ' Add the Order Count total to the data axis.
    vwView.DataAxis.InsertTotal totOrderCount
End Sub