Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Delete all worksheets but the summary

  Asked By: Anpu    Date: Jan 31    Category: MS Office    Views: 779
  

How can I adjust this code to delete all worksheets but the "Summary"
worksheet. Would seem more efficient than the path I've started down
below, which was to name all the worksheets BUT the Summary.

Sub DeleteWorksheets()
Application.DisplayAlerts = False
Sheets("Sheet1").Delete
ActiveSheet.Delete
Sheets("Sheet2").Delete
ActiveSheet.Delete
Application.DisplayAlerts = True
End Sub

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Alisha Johnson     Answered On: Jan 31

Watch out, there may be a few problems here. PLEASE backup everything
first.

Your code  is actually deleting two unnamed sheets as well as Sheet1 and
Sheet2 - look closely and you'll see why.

Here is code which would achieve it for you:

For Each sh in Sheets
If sh.Name <> "Summary" Then sh.Delete
Next sh

But another caution. Is your summary  sheet actually lifting values from
the other sheets. If so, delete  them and you'll get all sorts of errors
when the source sheets go missing. You might want to do a copy-paste
special-values on Summary before running the code.

 
Answer #2    Answered By: Varick Fischer     Answered On: Jan 31

Dim wrksht As Worksheet
Application.DisplayAlerts = False
For Each wrksht In Worksheets
If wrksht.Name <> "Summary" Then wrksht.Delete
Next
Application.DisplayAlerts = True

 
Didn't find what you were looking for? Find more on Delete all worksheets but the summary Or get search suggestion and latest updates.




Tagged: