Back to Devexpress

How to: Move a Worksheet to Another Location in a Workbook

windowsforms-15363-controls-and-libraries-spreadsheet-examples-worksheets-how-to-move-a-worksheet-to-another-location-in-a-workbook.md

latest2.2 KB
Original Source

How to: Move a Worksheet to Another Location in a Workbook

  • Dec 09, 2022

This example demonstrates how to move a worksheet to another location in a workbook. To do this, call the Worksheet.Move method and pass the worksheet zero-based index specifying the position in the WorksheetCollection collection into which the worksheet should be moved.

View Example

csharp
// Move the first worksheet to the position of the last worksheet within the workbook.
workbook.Worksheets[0].Move(workbook.Worksheets.Count - 1);
vb
' Move the first worksheet to the position of the last worksheet within the workbook.
workbook.Worksheets(0).Move(workbook.Worksheets.Count - 1)

You can also rearrange worksheets within a workbook by using methods inherited from the Sheet interface: Sheet.MoveToBeginning, Sheet.MoveBefore, Sheet.MoveAfter, and Sheet.MoveToEnd.

csharp
workbook.Worksheets[0].MoveToEnd();
vb
workbook.Worksheets(0).MoveToEnd()

The image below shows how the worksheet moves from the first position to the last position in the workbook.

See Also

Worksheets in Spreadsheet Documents