范围。合并方法 (Excel)Range.Consolidate method (Excel)

将多个工作表中多个区域的数据合并计算至单个工作表上的单个区域。Consolidates data from multiple ranges on multiple worksheets into a single range on a single worksheet. VariantVariant.

语法Syntax

表达式整合(函数TopRowLeftColumnCreateLinks)expression.Consolidate (Sources, Function, TopRow, LeftColumn, CreateLinks)

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

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
SourcesSources 可选Optional VariantVariant 以文本引用字符串数组的形式给出合并计算的源,该数组采用 R1C1-样式表示法。The sources of the consolidation as an array of text reference strings in R1C1-style notation. 这些引用必须包含将要合并计算的工作表的完整路径。The references must include the full path of sheets to be consolidated.
FunctionFunction 可选Optional VariantVariant XlConsolidationFunction 的常量之一, 指定合并类型。One of the constants of XlConsolidationFunction, which specifies the type of consolidation.
TopRowTopRow 可选Optional VariantVariant 如果为 True,则基于合并计算区域中首行内的列标题对数据进行合并。True to consolidate data based on column titles in the top row of the consolidation ranges. 如果为 False,则按位置进行合并计算。False to consolidate data by position. 默认值为 FalseThe default value is False.
LeftColumnLeftColumn 可选Optional VariantVariant 如果为 True 则基于合并计算区域中左列内的行标题对数据进行合并计算。True to consolidate data based on row titles in the left column of the consolidation ranges. 如果为 False,则按位置进行合并计算。False to consolidate data by position. 默认值为 FalseThe default value is False.
CreateLinksCreateLinks 可选Optional VariantVariant 如果为 True,则让合并计算使用工作表链接。True to have the consolidation use worksheet links. 如果为 False,则让合并计算复制数据。False to have the consolidation copy the data. 默认值为 FalseThe default value is False.

返回值Return value

VariantVariant

示例Example

本示例使用 SUM 函数将 Sheet2 和 Sheet3 中的数据合并到工作表 Sheet1 上。This example consolidates data from Sheet2 and Sheet3 onto Sheet1 by using the SUM function.

Worksheets("Sheet1").Range("A1").Consolidate _ 
 Sources:=Array("Sheet2!R1C1:R37C6", "Sheet3!R1C1:R37C6"), _ 
 Function:=xlSum

支持和反馈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.