VBA/Excel/Access/Word/Excel/Range Copy Cut Paste — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:33, 26 мая 2010
Содержание
- 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
Sub CopyRange2()
range("A1:A12").Copy range("C1")
End Sub
Copying a variably sized range
Sub CopyCurrentRegion2()
range("A1").CurrentRegion.Copy Sheets("Sheet2").range("A1")
End Sub
Copy method can use an argument for the destination range
Sub CopyCurrentRegion2()
Range("A1").CurrentRegion.Copy Sheets("Sheet1").Range("A1")
Application.CutCopyMode = False
End Sub
Copy method can use an argument that represents the destination for the copied range.
Sub CopyRange()
range("A1").Copy range("B1")
End Sub
Copy method has one argument - the destination range for the copy operation
Sub CopyOne()
Worksheets("Sheet1").Activate
range("A1").Copy range("B1")
End Sub
Moving a range
Sub MoveRange1()
range("A1:C6").Cut range("A10")
End Sub
Moving a range: move a range by cutting it to the Clipboard and then pasting it in another area
Sub MoveRange()
Range("A1:C6").Select
Selection.Cut
Range("A10").Select
ActiveSheet.Paste
End Sub
The Copy and Paste methods
Sub CopyRange()
range("A1:A12").Select
Selection.Copy
range("C1").Select
ActiveSheet.Paste
End Sub
To copy a range to a different worksheet or workbook, simply qualify the range reference for the destination.
Sub CopyRange2()
Workbooks("File1.xls").Sheets("Sheet1").range("A1").Copy Workbooks("File2.xls").Sheets("Sheet2").range("A1")
End Sub
You can move a range with a single VBA statement
Sub MoveRange2()
Range("A1:C6").Cut Range("A10")
End Sub