Archive of Mr Excel Message Board


Back to Pivot Tables in Excel archive index
Back to archive home

Delete all Sheets except a couple specifically named

Posted by Mark Farr on October 18, 2001 2:24 PM
I am using a pivot table and when you drill down it opens a new sheet. Sheet1, sheet2 etc. I want to give an option to close all drill down sheets but I won't know exactly how many are open therefore will not know all the names. How can I close (delete) them all and not delete the two sheets that I need. Thanks for your help.

Re: Delete all Sheets except a couple specifically named

Posted by Mark Farr on October 18, 2001 6:31 PM
This is a VBA question. Thanks for your help


Re: Delete all Sheets except a couple specifically named

Posted by Norbert Stiles on October 19, 2001 1:12 AM

sheets that I need. Thanks for your help.


Not sure exactly what you want to do, but this will delete all sheets except sheets "Sheet1" and "Sheet2" :-

Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" Then ws.Delete
Next
Application.DisplayAlerts = True


Thanks so much that worked great!

Posted by Mark Farr on October 19, 2001 8:14 AM


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.