Group Method

Applies To

Arcs Collection, Buttons Collection, ChartObjects Collection, DrawingObjects Collection, Drawings Collection, DropDowns Collection, EditBoxes Collection, GroupBoxes Collection, GroupObjects Collection, Labels Collection, Lines Collection, ListBoxes Collection, OLEObjects Collection, OptionButtons Collection, Ovals Collection, Pictures Collection, Range Object, Rectangles Collection, ScrollBars Collection, Spinners Collection, TextBoxes Collection.

Description

Syntax 1: Demotes a range in an outline (in other words, increases its outline level). The range should be an entire row or column, or a range of rows or columns.

Groups a discontinuous range in a PivotTable.

Groups multiple controls or drawing objects together; returns a new GroupObject object.

Syntax 2: Performs numeric or date grouping in a pivot field.

Syntax 1

object.Group

Syntax 2

object.Group(start, end, by, periods)

object

Required. The object to which this method applies. For syntax 2, the Range object must be a single cell in the data range of the pivot field. The method will fail (without displaying any error message) if you attempt to apply the method to more than one cell. To see how to use the Group method in this way, see the second example.

start

Optional. The first value to be grouped. If omitted or True, the first value in the field is used.

end

Optional. The last value to be grouped. If omitted or True, the last value in the field is used.

by

Optional. If the field is numeric, specifies the size of each group.

If the field is a date, specifies the number of days in each group if element four of the periods array is True. Otherwise by is ignored.

If this argument is omitted, a default group size is automatically chosen.

periods

Optional. An array of Boolean values specifying 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 of the array is True, a group is created for the corresponding time. If the element is False, no group is created. This argument is ignored if the field is not a date field.

See Also

OutlineLevel Property, Ungroup Method.

Example

This example creates a group from drawing objects one, three, and five on Sheet1.


Set myGroup = Worksheets("Sheet1").DrawingObjects(Array(1, 3, 5)).Group
Worksheets("Sheet1").Activate
myGroup.Select

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)