范围。 Group 方法 (Excel)Range.Group method (Excel)

如果Range对象代表数据透视表字段的数据区域中的单个单元格, 则Group方法在该字段中执行基于数字或日期的分组。When the Range object represents a single cell in a PivotTable field's data range, the Group method performs numeric or date-based grouping in that field.

语法Syntax

表达式(StartEndBy句号)expression.Group (Start, End, By, Periods)

expression 一个表示 Range 对象的变量。expression A variable that represents a Range object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
StartStart 可选Optional VariantVariant 要分组的第一个值。The first value to be grouped. 如果该参数被省略或为 True,则使用字段中的第一个值。If this argument is omitted or True, the first value in the field is used.
EndEnd 可选Optional VariantVariant 要分组的最后一个值。The last value to be grouped. 如果该参数被省略或为 True,则使用字段中的最后一个值。If this argument is omitted or True, the last value in the field is used.
ByBy 可选Optional VariantVariant 如果字段为数字,则该参数指定每个组的大小。If the field is numeric, this argument specifies the size of each group. 如果该字段是日期, 则此参数指定每个组中的天数, 如果_句点_数组中的元素4为True , 其他所有元素均为FalseIf 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. 如果省略此参数,Microsoft Excel 将自动选择一个默认的组大小。If this argument is omitted, Microsoft Excel automatically chooses a default group size.
课时Periods 可选Optional VariantVariant 一个 Boolean 值的数组,用于指定组的期限,如“备注”部分所示。An array of Boolean values that specify the period for the group, described in the Remarks section. 如果数组中的元素为 True,则为相应的时间创建组;如果元素为 False,则不创建组。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.

返回值Return value

VariantVariant

注解Remarks

Periods 参数的 Boolean 数组,其中包含以下元素:The Boolean array for the Periods parameter contains the following elements:

数组元素Array element 句点Period
11 Seconds
双面2 分钟Minutes
第三章3 工作时间Hours
44 Days
55 Months
6 季度Quarters
7 Years

由于一组形状作为单个形状处理,所以创建和分解形状组将更改 Shapes 集合中的项目数,并更改集合中受影响的项目之后的项目索引号。Because a group of shapes is treated as a single shape, grouping and ungrouping shapes changes the number of items in the Shapes collection and changes the index numbers of items that come after the affected items in the collection.

Range对象必须是数据透视表字段的数据区域中的单个单元格。The Range object must be a single cell in the PivotTable field's data range. 如果试图对多个单元格应用该方法,将会失败(不显示错误消息)。If you attempt to apply this method to more than one cell, it will fail (without displaying an error message).

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.