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
Solved

Delete all sheets except defined ones

Posted on 2011-03-13
4
449 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
question about excel functionality 3 33
VBA Vbscript  Issue 9 25
save excel in the same active file's folder. 8 23
Copy and Paste Text into Text Box 3 26
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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