GroupEnd Property

Microsoft Office Web Components Visual Basic

expression.GroupEnd

expression    Required. An expression that returns a PivotField object.

Remarks

If the specified field contains values greater than the setting for this property, then a group titled ">=(GroupEnd +1)" is created where GroupEnd is the value specified for this property. This group will contain all values that are greater than the setting for this property.

If this property is not set or is set to Empty, then the largest value in the field is used as the ending value.

If the current setting for the GroupOn property is plGroupOnPrefixChars, then you will receive a run-time error when you set this property.

Example

This example groups the Age field of PivotTable1. Starting at age 15, a new group will be created for every five years until age 80. Then, the font, foreground, background, height and alignment of the resulting groups are formatted.

Sub AddGrouping()

    Dim vwView
    Dim ptConstants
    Dim pfGroupedField

    Set ptConstants = PivotTable1.Constants

    ' Set a variable to the active view of the PivotTable.
    Set vwView = PivotTable1.ActiveView
    
    ' Set a variable to the Age field.
    Set pfGroupedField = vwView.FieldSets("Age").Fields("Age")
    
    ' Set the GroupOn property so that the Age field will be
    ' grouped by the GroupInterval setting.
    pfGroupedField.GroupOn = ptConstants.plGroupOnInterval

    ' Create a new grouping for every five years.
    pfGroupedField.GroupInterval = 5

   ' Start the grouping at age 15.
    pfGroupedField.GroupStart = 15

    ' End the grouping at age 80.
    pfGroupedField.GroupEnd = 80
    
    ' Set the font for the field when it is grouped.
    pfGroupedField.GroupedFont.Bold = True

    ' Set the foreground color for the field when it is grouped.
    pfGroupedField.GroupedForeColor = "Black"

    ' Set the Background color for the field when it is grouped.
    pfGroupedField.GroupedBackColor = "Blue"

    ' Set the height for the field when it is grouped.
    pfGroupedField.GroupedHeight = 15

    ' Set the horizontal alignment for the field when it is grouped.
    pfGroupedField.GroupedHAlignment = ptConstants.plHAlignRight
    
End Sub