Solved

Delete all sheets except defined ones

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Finding a closest match in Excel 7 48
EXCEL 2013 question. 4 28
macro modification Column C 14 31
EXCEL formual to calculate Quarter 6 37
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

809 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