Range.Copy Method (Excel)
Copies the range to the specified range or to the Clipboard.
Syntax
식 .Copy(Destination)
식 A variable that represents a Range object.
Parameters
Name |
Required/Optional |
Data Type |
Description |
---|---|---|---|
Destination |
선택 |
Variant |
Specifies the new range to which the specified range will be copied. If this argument is omitted, Microsoft Excel copies the range to the Clipboard. |
Return Value
Variant
Example
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")
Sample code provided by: Bill Jelen, MrExcel.com | About the Contributor
The following code example inspects the value in column D for each row in Sheet1. If the value in column D equals "A" the entire row is copied onto SheetA, in the next empty row. 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
About the Contributor
MVP인 Bill Jelen은 Microsoft Excel에 대한 서적을 다수 집필했습니다. 또한 Leo Laporte와 함께 TechTV에 고정 출연하고 있으며, Excel과 관련한 30만 건 이상의 질문과 대답이 제공되는 MrExcel.com(영문일 수 있음)의 운영자이기도 합니다.