Solved

Delete some sheets but keep others

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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,…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 the scrolling table in Microsoft Excel using the INDEX function.

770 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