Solved

Delete all sheets except defined ones

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

758 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now