Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: Cannot Move or Copy Sheet After Last Sheet


View products that this article applies to.

This article was previously published under Q213604

↑ Back to the top


Symptoms

When you run a Microsoft Visual Basic for Applications macro that copies or moves a worksheet or a chart sheet after the last worksheet in the workbook, or if you attempt to do this manually, Microsoft Excel does not insert the copied or moved worksheet after the last worksheet in the workbook.

↑ Back to the top


Cause

This behavior occurs when the last worksheet in the workbook is hidden. This behavior is by design of Microsoft Excel.

↑ Back to the top


Workaround

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To prevent this behavior from occurring, move all hidden sheets to the front in the order of sheet tabs in the workbook. To do this manually, unhide all hidden sheets, drag the sheet tabs to the left (in front of the other tabs), and then rehide the sheets.

To unhide a sheet, follow these steps:
  1. On the Format menu, point to Sheet, and then click Unhide.
  2. Click the name of the sheet you want to unhide and click OK.
To hide a sheet, follow these steps:
  1. Activate the sheet.
  2. On the Format menu, point to Sheet, and click Hide.
Alternatively, you can use the following Visual Basic for Applications macro to move all hidden sheets to the beginning of the workbook:
   Sub MoveHiddenSheets()
       For Each xSheet In ActiveWorkbook.Sheets
           If xSheet.Visible = False Then
               xSheet.Move Before:=Sheets(1)
           End If
       Next xSheet
   End Sub
				

↑ Back to the top


More information

If Microsoft Excel, you can use the Copy and Move methods within a Visual Basic macro to copy or move sheets within a single workbook or to another workbook. You can also copy or move sheets by clicking Move or Copy Sheet on the Edit menu.

In versions of Microsoft Excel earlier than Excel 97, you can copy or move a sheet after the other sheets in the workbook programmatically by using one of the following commands in a macro:
   Sheets("Sheetname").Copy After:=Sheets(Sheets.Count)

   -or-

   Sheets("Sheetname").Move After:=Sheets(Sheets.Count)
				

In Microsoft Excel 2000, if you run a macro that contains either of these commands, and the last sheet in the workbook is hidden, the copied or moved sheet is not inserted at the end of the workbook. Instead, the sheet is moved to the right of the last visible sheet in the workbook.

The same behavior applies if you click Move or Copy Sheet on the Edit menu, click (move to end) and then click OK. In Microsoft Excel 2000, the copied or moved sheet is moved to the right of the last visible sheet in the workbook. In versions of Microsoft Excel earlier than Excel 97, the copied or moved sheet is moved to the end of the workbook.

↑ Back to the top


Keywords: KB213604, kbprb, kbdtacode

↑ Back to the top

Article Info
Article ID : 213604
Revision : 6
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 238