How to Copy Cells

The "Copy cell" feature allows you to duplicate the contents of a cell and paste them into one or more other cells. It is a convenient way to replicate data, formulas, formatting, or other attributes within the worksheet.

Additionally, the Copy method also retains styling, enabling efficient and accurate data replication within a single or multiple worksheets using IronXL.


Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


Copy a Single Cell Example

To copy the content of a selected cell, you can use the Copy method. Pass the worksheet object as the first parameter and the starting position as the second parameter. The Copy method also retains any styling that the cell contains.

:path=/static-assets/excel/content-code-examples/how-to/copy-cells-copy-single-cell.cs
using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Copy cell content
workSheet["A1"].Copy(workBook.GetWorkSheet("Sheet1"), "B3");

workBook.SaveAs("copySingleCell.xlsx");
Imports IronXL

Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")

' Copy cell content
workSheet("A1").Copy(workBook.GetWorkSheet("Sheet1"), "B3")

workBook.SaveAs("copySingleCell.xlsx")
$vbLabelText   $csharpLabel

Output Spreadsheet

Copy Single Cell

Copy Cell Range Example

Similar to the Clear method, this method is also available in the Range class, allowing you to execute it on any range, regardless of its size. Here are some examples:

  • Copy a single cell (C10):

    workSheet["C10"].Copy(workBook.GetWorkSheet("Sheet1"), "B13");
    workSheet["C10"].Copy(workBook.GetWorkSheet("Sheet1"), "B13");
    workSheet("C10").Copy(workBook.GetWorkSheet("Sheet1"), "B13")
    $vbLabelText   $csharpLabel
  • Copy a column (A):

    workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1");
    workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1");
    workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1")
    $vbLabelText   $csharpLabel
  • Copy a row (4):

    workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15");
    workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15");
    workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15")
    $vbLabelText   $csharpLabel
  • Copy a two-dimensional range (D6:F8):

    workSheet["D6:F8"].Copy(workBook.GetWorkSheet("Sheet1"), "H17");
    workSheet["D6:F8"].Copy(workBook.GetWorkSheet("Sheet1"), "H17");
    workSheet("D6:F8").Copy(workBook.GetWorkSheet("Sheet1"), "H17")
    $vbLabelText   $csharpLabel

Please note
The second parameter accepts an address location that marks the starting point of data entry. The copied data will start from that address and spread rightward and downward.

:path=/static-assets/excel/content-code-examples/how-to/copy-cells-copy-cell-range.cs
using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Copy a single cell(C10)
workSheet["C10"].Copy(workBook.GetWorkSheet("Sheet1"), "B13");

// Copy a column(A)
workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1");

// Copy a row(4)
workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15");

// Copy a two-dimensional range(D6:F8)
workSheet["D6:F8"].Copy(workBook.GetWorkSheet("Sheet1"), "H17");

workBook.SaveAs("copyCellRange.xlsx");
Imports IronXL

Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")

' Copy a single cell(C10)
workSheet("C10").Copy(workBook.GetWorkSheet("Sheet1"), "B13")

' Copy a column(A)
workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1")

' Copy a row(4)
workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15")

' Copy a two-dimensional range(D6:F8)
workSheet("D6:F8").Copy(workBook.GetWorkSheet("Sheet1"), "H17")

workBook.SaveAs("copyCellRange.xlsx")
$vbLabelText   $csharpLabel

Output Spreadsheet

Copy Cell Range

Copy Cell Across Worksheet Example

Since the first parameter accepts a worksheet object, it is possible to copy and paste a cell range across different worksheets. Simply pass a different worksheet object as the first parameter.

Please note
In the following example, the first parameter of the Copy method is the "Sheet2" worksheet: workBook.GetWorksheet("Sheet2")

// Example Code: Copy cells across different worksheets in IronXL

using IronXL;

:path=/static-assets/excel/content-code-examples/how-to/copy-cells-copy-to-other-worksheet.cs
// Example Code: Copy cells across different worksheets in IronXL

using IronXL;

using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Copy cell content
workSheet["A1"].Copy(workBook.GetWorkSheet("Sheet2"), "B3");

workBook.SaveAs("copyAcrossWorksheet.xlsx");
' Example Code: Copy cells across different worksheets in IronXL

Imports IronXL


Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")

' Copy cell content
workSheet("A1").Copy(workBook.GetWorkSheet("Sheet2"), "B3")

workBook.SaveAs("copyAcrossWorksheet.xlsx")
$vbLabelText   $csharpLabel

Frequently Asked Questions

How do I copy a single cell using a C# library?

To copy a single cell using IronXL, use the `Copy` method. Pass the worksheet object as the first parameter and the starting position as the second parameter. This method retains any cell styling.

Can I copy a whole column using a C# library?

Yes, you can copy a whole column using IronXL. Use the `Copy` method on the column range and specify the destination worksheet and position.

How do I copy a row in a C# library?

To copy a row in IronXL, use the `GetRow` method to select the row, then use the `Copy` method to specify the destination worksheet and position.

Is it possible to copy a range of cells in a C# library?

Yes, IronXL allows you to copy a range of cells using the `Copy` method. Specify the range and the destination worksheet and starting position.

Can I copy cells across different worksheets in a C# library?

Yes, you can copy cells across different worksheets by passing the destination worksheet object as the first parameter in the `Copy` method.

Does the Copy method in a C# library retain cell formatting?

Yes, the Copy method in IronXL retains the styling and formatting of the cells that are being copied.

What library do I need to install to use for copying cells?

You need to download and install the IronXL Excel library from NuGet to use its functionalities for copying cells.

What code do I use to copy a cell range from one worksheet to another?

Use the `Copy` method to specify the range and the destination worksheet and starting position. For example: `sourceSheet["D6:F8"].Copy(destinationSheet, "H17");`

How do I specify the destination position when copying cells in a C# library?

The second parameter of the `Copy` method specifies the starting address in the destination worksheet where the copied data will begin.

Is it possible to automate the process of copying cells in C#?

Yes, IronXL allows you to automate the process of copying cells in C# by using methods like `Copy` along with other IronXL functionalities.

Chaknith related to Copy Cell Across Worksheet Example
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.