Copy And Paste Ranges Of Cells

You can copy and paste cell ranges within a worksheet using the Copy method. The Copy method is essentially the same as the Copy and Paste commands within Excel, except that in Excel you are required to use two commands;that is, you first copy the desired range and move to the appropriate location, and then select the Paste command.

The Copy method associated with the Range object provides the ability to copy the values from a specific range and paste the values either in the Windows Clipboard or a specific destination. The Copy method has one optional parameter, Destination, that you can use if you want to specify where the copied values should be pasted. If you do not specify a Destination parameter value, the copied range of values is pasted in the Windows Clipboard. If you use the Destination parameter, you must specify another Range object as the location for the values to be pasted. The following code illustrates the use of the Copy method to paste the range in cells A1:A5: CopyRange.Copy Destination:=Range( "A1:A5 ")

Keep in mind that the range specified from the CutRange variable and the destination range must be the same size, or Excel returns an error.

If you do not know the size of the copied range of cells, you can specify a single cell as the destination range: CopyRange. Copy Destination:=Range("A1")

If you specify only one cell, Excel uses the specified cell as the initial cell and pastes the values in cells starting at that location. In other words, if pasting the contents requires cells A1:B4, Excel automatically uses those cells.

When you use the Copy method, the contents remain in the original cells, and a copy of those values is pasted in the new cells.

COPY AND PASTE A RANGE OF CELLS

COPY AND PASTE A RANGE OF CELLS

'-n Create a new subroutine.

0 Type Dim CopyRange As Range, replacing CopyRange with the variable containing the range to copy.

L0 Type Set CopyRange = Range("E1:F5"), replacing Range("E1:F5") with the range to copy.

'-n Create a new subroutine.

Note: See Chapter 3 for information on creating subroutines.

0 Type Dim CopyRange As Range, replacing CopyRange with the variable containing the range to copy.

L0 Type Set CopyRange = Range("E1:F5"), replacing Range("E1:F5") with the range to copy.

0 0

Post a comment