Solved

Delete all sheets except defined ones

Posted on 2011-03-13
4
466 Views
Last Modified: 2012-05-11
I need to run a macro that will delete all sheets except those named..

"WEEK1", "WEEK2", "WEEK3", "WEEK4", "WEEK5", "MONTH", strCurrentContractors, strCreateReport, strExceptions, strExchangeRate, strSummary, strTemplate

Regards,
Antonio King
0
Comment
Question by:antonioking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 35121689
Like this perhaps:
Sub x()

Dim ws As Worksheet

For Each ws In Worksheets
    Select Case ws.Name
        Case "WEEK1", "WEEK2", "WEEK3", "WEEK4", "WEEK5", "MONTH", _
             strCurrentContractors, strCreateReport, strExceptions, strExchangeRate, _
             strSummary, strTemplate
            ' do nothing
        Case Else
            Application.DisplayAlerts = False
            ws.Delete
            Application.DisplayAlerts = True
    End Select
Next ws

End Sub

Open in new window

0
 

Author Comment

by:antonioking
ID: 35121735
Thanks, how do I stop excel asking for comfirmation to delete the sheet?
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 35121739
Line 12 should do that. Are you saying you get the message every time?
0
 

Expert Comment

by:cbsbutler
ID: 35121859
I left those lines out! Added in now and working. Thanks v much!

Antonio King
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question