Solved

Delete some sheets but keep others

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
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.

743 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

11 Experts available now in Live!

Get 1:1 Help Now