NativeExcel for .Net Developer's Reference

IRange.CopyMethod(Object, XlPasteType)

Copies a cell or a range of cells to the specified range.

[Visual Basic]
SubCopy(_
ByValDestinationAsObject,_
ByValPasteModeAsXlPasteType_
)
[C#]
voidCopy(
objectDestination,
XlPasteTypePasteMode
);
[C++]
voidCopy(
Object*Destination,
XlPasteTypePasteMode
);
[JScript]
functionCopy(
ObjectDestination,
XlPasteTypePasteMode
);

Parameters

Destination
Specifies the new range to which the specified range will be copied. Can be either an IRange interface or String which represents a range.
PasteMode
XlPasteType. Indicates the part of the range to be copied.

Example

This example copies the values of range A1:D4 on Sheet1 into range E5:H8 on Sheet2.

[C#]
 IRange dstrange = book.Worksheets["Sheet2"].Range["E5:H8"];
 book.Worksheets["Sheet1"].Range["A1:D4"].Copy(dstrange, XlPasteType.xlPasteValues); 
[VisualBasic]
 Dim dstrange As IRange = book.Worksheets("Sheet2").Range("E5:H8")
 book.Worksheets("Sheet1").Range("A1:D4").Copy(dstrange, XlPasteType.xlPasteValues)
[C++]
 IRange* dstrange = book->Worksheets->Item[S"Sheet2"]->Range->Item[S"E5:H8"];
 book->Worksheets->Item[S"Sheet1"]->Range->Item[S"A1:D4"]->Move(dstrange, XlPasteType::xlPasteValues); 
This example copies the values of range A1:D4 on Sheet1 into range E5:H8 on the same sheet.
[C#]
 IWorksheet sheet = book.Worksheets["Sheet1"];
 sheet.Range["A1:D4"].Copy("E5:H8", XlPasteType.xlPasteValues);
[VisualBasic]
 Dim sheet As IWorksheet = book.Worksheets("Sheet1")
 sheet.Range("A1:D4").Copy("E5:H8", XlPasteType.xlPasteValues)
[C++]
 IWorksheet* sheet = book->Worksheets->Item[S"Sheet1"];
 sheet->Range->Item[S"A1:D4"]->Copy(S"E5:H8", XlPasteType::xlPasteValues);     
This example copies the formats of range A1:D4 on Sheet1 into range E5:H8 on the same sheet.
[C#]
 IWorksheet sheet = book.Worksheets["Sheet1"];
 sheet.Range["A1:D4"].Copy("E5:H8", XlPasteType.xlPasteFormats);
[VisualBasic]
 Dim sheet As IWorksheet = book.Worksheets("Sheet1")
 sheet.Range("A1:D4").Copy("E5:H8", XlPasteType.xlPasteFormats)
[C++]
 IWorksheet* sheet = book->Worksheets->Item[S"Sheet1"];
 sheet->Range->Item[S"A1:D4"]->Copy(S"E5:H8", XlPasteType::xlPasteFormats);     

See Also

IRange Interface | NativeExcel Namespace | IRange.Copy Overload List | XlPasteType Enumeration