VBA/Excel/Access/Word/Excel/Range Copy Cut Paste — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:47, 26 мая 2010

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