Solved

Delete some sheets but keep others

Posted on 2015-02-10
2
90 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

679 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