# Repeatedly Filling a Range of Cells with Copied Cells

Learn how to use the FillRange method to efficiently copy and fill a range of cells in your spreadsheets.

## Content

You can copy a range of cells and fill another range with those cells, copying the data and the cell type with the [FillRange](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.FillRange.html) method. For example, if you have a 2x2 range, you can repeat (fill) down the next five groups of 2x2 vertically.
The parameters for the [FillRange](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.FillRange.html) method are:

* starting cell row and column index
* number of rows and columns in the range to copy
* number of either rows (if left or right) or columns (if up or down) to copy that range (not the number of times to repeat the entire range; the number of either rows or columns)

![Ranges of Cells Filled](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/cells-fillrange-labels.png)

## Using Code

1. Add data to the cells.
2. Set the [FillRange](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.SheetView.FillRange.html) method.

## Example

For example, using this code, you would accomplish the results shown in the preceding figure.

```csharp
// Define the text to repeat.
fpSpread1.ActiveSheet.Cells[0, 0].Text = "A1-text";
fpSpread1.ActiveSheet.Cells[0, 1].Text = "A2-text";
fpSpread1.ActiveSheet.Cells[1, 0].Text = "B1-text";
fpSpread1.ActiveSheet.Cells[1, 1].Text = "B2-text";

fpSpread1.ActiveSheet.Cells[0, 0].BackColor = Color.Cyan;
fpSpread1.ActiveSheet.Cells[0, 0].ForeColor = Color.DarkBlue;
fpSpread1.ActiveSheet.Cells[0, 1].BackColor = Color.Coral;
fpSpread1.ActiveSheet.Cells[0, 1].ForeColor = Color.DarkRed;

// Fill 3 more columns to the right with the two columns' contents
fpSpread1.ActiveSheet.FillRange(0, 1, 2, 1, 3, FarPoint.Win.Spread.FillDirection.Right);
// Fill 4 more rows down with the contents of the square
// of 2 rows and 2 columns
fpSpread1.ActiveSheet.FillRange(0, 0, 2, 2, 4, FarPoint.Win.Spread.FillDirection.Down);
```

```vbnet
' Define the text to repeat.
fpSpread1.ActiveSheet.Cells(0, 0).Text = "A1-text"
fpSpread1.ActiveSheet.Cells(0, 1).Text = "A2-text"
fpSpread1.ActiveSheet.Cells(1, 0).Text = "B1-text"
fpSpread1.ActiveSheet.Cells(1, 1).Text = "B2-text"

fpSpread1.ActiveSheet.Cells(0, 0).BackColor = Color.Cyan
fpSpread1.ActiveSheet.Cells(0, 0).ForeColor = Color.DarkBlue
fpSpread1.ActiveSheet.Cells(0, 1).BackColor = Color.Coral
fpSpread1.ActiveSheet.Cells(0, 1).ForeColor = Color.DarkRed

' Fill 3 more columns to the right with the two columns' contents
fpSpread1.ActiveSheet.FillRange(0, 1, 2, 1, 3, FarPoint.Win.Spread.FillDirection.Right)
' Fill 4 more rows down with the contents of the square
' of 2 rows and 2 columns
fpSpread1.ActiveSheet.FillRange(0, 0, 2, 2, 4, FarPoint.Win.Spread.FillDirection.Down)
```

## See Also

[Customizing Clipboard Operation Options](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-ssobject-sheet/spwin-cntrlclipopts)
[Copying Data on a Sheet](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-ssobject-cell/spwin-usedata/spwin-datacopy)