Range。 Insert 方法 (Excel)Range.Insert method (Excel)

在工作表或宏表中插入一个单元格或单元格区域,其他单元格相应移位以腾出空间。Inserts a cell or a range of cells into the worksheet or macro sheet and shifts other cells away to make space.

语法Syntax

表达式Insert(ShiftCopyOrigin)expression.Insert (Shift, CopyOrigin)

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

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
ShiftShift 可选Optional VariantVariant 指定单元格的调整方式。Specifies which way to shift the cells. 可以是下列的**XlInsertShiftDirection** 常量之一: xlShiftToRightxlShiftDownCan be one of the following XlInsertShiftDirection constants: xlShiftToRight or xlShiftDown. 如果省略此参数,Microsoft Excel 将根据区域的形状确定调整方式。If this argument is omitted, Microsoft Excel decides based on the shape of the range.
CopyOriginCopyOrigin 可选Optional VariantVariant 副本源;也就是说, 从何处复制插入单元格的格式。The copy origin; that is, from where to copy the format for inserted cells. 可以是下列的**XlInsertFormatOrigin** 常量之一: xlFormatFromLeftOrAbove (默认值) 或xlFormatFromRightOrBelowCan be one of the following XlInsertFormatOrigin constants: xlFormatFromLeftOrAbove (default) or xlFormatFromRightOrBelow.

返回值Return value

VariantVariant

注解Remarks

在 Excel 中以交互方式插入单元格时, CopyOrigin_的值等效于_清除格式There is no value for CopyOrigin that is equivalent to Clear Formatting when inserting cells interactively in Excel. 若要实现此目的, 请使用**ClearFormats** 方法。To achieve this, use the ClearFormats method.

With Range("B2:E5")
    .Insert xlShiftDown
    .ClearFormats
End With

示例Example

本示例在第2行上方插入一行, 从下一行 (行 3) 而不是从标题行复制格式。This example inserts a row above row 2, copying the format from the row below (row 3) instead of from the header row.

Range("2:2").Insert CopyOrigin:=xlFormatFromRightOrBelow

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