AddCustomGroupField Method

Microsoft Office Web Components Visual Basic

expression.AddCustomGroupField(Name, Caption, Before)

expression    Required. An expression that returns a PivotFieldSet object.

Name   Optional String. The name for the new field.

Caption   Optional String. The caption to display for the new field.

Before   Optional Variant. Index, name, or reference to the field.

Remarks

Once you have used this method to create a custom group field, use the AddCustomGroupMember method to add members to the group.

Note that the custom group field and its members are created at the client, not the data source.

Example

This example adds a custom group field to the Time field set, and then adds two members to the field.

Sub CreateCustomGroup()

   Dim fsTime
   Dim fsHalfYear

   ' Set a variable to the Time field set.
   Set fsTime = PivotTable1.ActiveView.FieldSets("Time")

   ' Add a custom group field named "Group1" to the Time field set.
   Set fsHalfYear = fsTime.AddCustomGroupField("Group1", "Group1", _
                    "Quarter")
    
   ' Add a member to the custom field set. This member includes all "Q1"
   ' and "Q2" members under 1997.
   fsHalfYear.AddCustomGroupMember fsTime.Member.Childmembers("1997").Name, _
                                   Array("Q1","Q2"), "1stHalf"

   ' Add a member to the custom field set. This member includes all "Q3"
   ' and "Q4" members under 1997.
   fsHalfYear.AddCustomGroupMember fsTime.Member.ChildMembers("1997").Name, _
                                   Array("Q3","Q4"), "2ndHalf"    

End Sub