VBA/Excel/Access/Word/Excel/Range Copy Cut Paste
Содержание
- 1 Copy a range
- 2 Copying a variably sized range
- 3 Copy method can use an argument for the destination range
- 4 Copy method can use an argument that represents the destination for the copied range.
- 5 Copy method has one argument - the destination range for the copy operation
- 6 Moving a range
- 7 Moving a range: move a range by cutting it to the Clipboard and then pasting it in another area
- 8 The Copy and Paste methods
- 9 To copy a range to a different worksheet or workbook, simply qualify the range reference for the destination.
- 10 You can move a range with a single VBA statement
Copy a range
<source lang="vb">
Sub CopyRange2()
range("A1:A12").Copy range("C1")
End Sub
</source>
Copying a variably sized range
<source lang="vb">
Sub CopyCurrentRegion2()
range("A1").CurrentRegion.Copy Sheets("Sheet2").range("A1")
End Sub
</source>
Copy method can use an argument for the destination range
<source lang="vb">
Sub CopyCurrentRegion2()
Range("A1").CurrentRegion.Copy Sheets("Sheet1").Range("A1") Application.CutCopyMode = False
End Sub
</source>
Copy method can use an argument that represents the destination for the copied range.
<source lang="vb">
Sub CopyRange()
range("A1").Copy range("B1")
End Sub
</source>
Copy method has one argument - the destination range for the copy operation
<source lang="vb">
Sub CopyOne()
Worksheets("Sheet1").Activate range("A1").Copy range("B1")
End Sub
</source>
Moving a range
<source lang="vb">
Sub MoveRange1()
range("A1:C6").Cut range("A10")
End Sub
</source>
Moving a range: move a range by cutting it to the Clipboard and then pasting it in another area
<source lang="vb">
Sub MoveRange()
Range("A1:C6").Select Selection.Cut Range("A10").Select ActiveSheet.Paste
End Sub
</source>
The Copy and Paste methods
<source lang="vb">
Sub CopyRange()
range("A1:A12").Select Selection.Copy range("C1").Select ActiveSheet.Paste
End Sub
</source>
To copy a range to a different worksheet or workbook, simply qualify the range reference for the destination.
<source lang="vb">
Sub CopyRange2()
Workbooks("File1.xls").Sheets("Sheet1").range("A1").Copy Workbooks("File2.xls").Sheets("Sheet2").range("A1")
End Sub
</source>
You can move a range with a single VBA statement
<source lang="vb">
Sub MoveRange2()
Range("A1:C6").Cut Range("A10")
End Sub
</source>