Group Method (Range Object)
Applies To
Range object.
Description
When the Range object is in an outline, the Group method (Syntax 1) demotes the range (in other words, increases its outline level). The range should be an entire row or column, or a range of rows or columns.
When the Range object is a discontinuous range in a PivotTable, the Group method (Syntax 1) groups the range.
When the Range object represents a single cell in the pivot field's data range, the Group method (Syntax 2) performs numeric or date-based grouping in a pivot field.
Syntax 1
expression.Group
Syntax 2
expression.Group(Start, End, By, Periods)
expression Required. An expression that returns a Range object. For Syntax 2, the Range object must be a single cell in the pivot field's data range. If you attempt to apply this method to more than one cell, it will fail (without displaying an error message).
Start Optional Variant. The first value to be grouped. If this argument is omitted or True, the first value in the field is used.
End Optional Variant. The last value to be grouped. If this argument is omitted or True, the last value in the field is used.
By Optional Variant. If the field is numeric, this argument specifies the size of each group.
If the field is a date, this argument specifies the number of days in each group if element 4 in the Periods array is True and all the other elements are False. Otherwise, this argument is ignored.
If this argument is omitted, Microsoft Excel automatically chooses a default group size.
Periods Optional Variant. An array of Boolean values that specify the period for the group, as shown in the following table.
Array element | Period |
|
1 | Seconds |
2 | Minutes |
3 | Hours |
4 | Days |
5 | Months |
6 | Quarters |
7 | Years |
If an element in the array is True, a group is created for the corresponding time; if the element is False, no group is created. If the field isn't a date field, this argument is ignored.
See Also
ApplyOutlineStyles method, AutoOutline method, ClearOutline method, DisplayOutline property, Outline object, OutlineLevel property, ShowDetail property, Ungroup method.
Example
This example groups the field named "ORDER_DATE" by 10-day periods.
Set pvtTable = Worksheets("Sheet1").Range("A3").PivotTable
Set groupRange = pvtTable.PivotFields("ORDER_DATE").DataRange
groupRange.Cells(1).Group by:=10, periods:=Array _
(False, False, False, True, False, False, False)