Solved

Delete some sheets but keep others

Posted on 2015-02-10
2
87 Views
Last Modified: 2016-02-10
I need vba code that will delete certain sheets but I won't know what their names are.

I do know I need to keep sheets named Start, Raw Data, Static and Age Sheet.

Any other sheet in the workbook needs to be deleted

Can an expert assist please.

Thanks
0
Comment
Question by:Jagwarman
2 Comments
 
LVL 19

Accepted Solution

by:
helpfinder earned 500 total points
ID: 40600351
Try this macro

Sub DeleteSheets()

    Dim ws As Worksheet
   
    Application.DisplayAlerts = False   'Optional
   
    For Each ws In Worksheets
        Select Case ws.Name
            'Include sheet names to keep on next line (with comma between)
            Case "Start", "Raw Data", "Static", "Age Sheet"
                'Do nothing
            Case Else
                ws.Delete
        End Select
    Next ws

    Application.DisplayAlerts = True
   
End Sub

Open in new window

0
 

Author Closing Comment

by:Jagwarman
ID: 40600400
great that works perfect.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

867 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

12 Experts available now in Live!

Get 1:1 Help Now