Solved

Delete some sheets but keep others

Posted on 2015-02-10
2
92 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

623 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