Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

How to: Programmatically Move Worksheets Within Workbooks

You can programmatically change the position of worksheets relative to other worksheets in a workbook. If you do not specify a location for the moved sheet, Excel creates a new workbook to contain it.

Applies to: The information in this topic applies to document-level projects and application-level projects for Excel 2013 and Excel 2010. For more information, see Features Available by Office Application and Project Type.

To move a worksheet in a document-level customization

  • Assign the total number of sheets in the workbook to a variable and then move the first worksheet so that it becomes the last one.

    int totalSheets = this.Application.ActiveWorkbook.Sheets.Count;
    Globals.Sheet1.Move(Globals.ThisWorkbook.Sheets[totalSheets]);
    

To move a worksheet in an application-level add-in

  • Assign the total number of sheets in the workbook to a variable and then move the first worksheet so that it becomes the last one.

    int totalSheets = this.Application.ActiveWorkbook.Sheets.Count;
    ((Excel.Worksheet)Application.ActiveSheet).Move(
        this.Application.Worksheets[totalSheets]);
    
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.