Range.Copy 方法 (Excel)Range.Copy method (Excel)

将区域复制到指定的区域或剪贴板。Copies the range to the specified range or to the Clipboard.

语法Syntax

expression.Copy (Destination)expression.Copy (Destination)

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

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
DestinationDestination 可选Optional VariantVariant 指定要将指定区域复制到的新区域。Specifies the new range to which the specified range will be copied. 如果省略此参数,则 Microsoft Excel 会将区域复制到剪贴板。If this argument is omitted, Microsoft Excel copies the range to the Clipboard.

返回值Return value

VariantVariant

示例Example

以下代码示例将工作表 Sheet1 上单元格 A1:D4 中的公式复制到工作表 Sheet2 上的单元格 E5:H8 中。The following code example copies the formulas in cells A1:D4 on Sheet1 into cells E5:H8 on Sheet2.

Worksheets("Sheet1").Range("A1:D4").Copy _ 
    destination:=Worksheets("Sheet2").Range("E5")

下面的代码示例检查 Sheet1 中各行 D 列中的值。The following code example inspects the value in column D for each row on Sheet1. 如果 D 列的值等于 A,则整行都复制到 SheetA 的下一个空行中。If the value in column D equals "A" the entire row is copied onto SheetA, in the next empty row. 如果值等于 B,则该行复制到 SheetB。If the value equals "B" the row is copied onto SheetB.

Public Sub CopyRows() 
    Sheets("Sheet1").Select 
    ' Find the last row of data 
    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row 
    ' Loop through each row 
    For x = 2 To FinalRow 
        ' Decide if to copy based on column D 
        ThisValue = Cells(x, 4).Value 
        If ThisValue = "A" Then 
            Cells(x, 1).Resize(1, 33).Copy 
            Sheets("SheetA").Select 
            NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1 
            Cells(NextRow, 1).Select 
            ActiveSheet.Paste 
            Sheets("Sheet1").Select 
        ElseIf ThisValue = "B" Then 
            Cells(x, 1).Resize(1, 33).Copy 
            Sheets("SheetB").Select 
            NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1 
            Cells(NextRow, 1).Select 
            ActiveSheet.Paste 
            Sheets("Sheet1").Select 
        End If 
    Next x 
End Sub

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