+ Reply to Thread
Results 1 to 4 of 4

I need to delete any worksheets that are not specified on a list in the first worksheet.

  1. #1
    Registered User
    Join Date
    11-13-2015
    Location
    Indiana, U.S.
    MS-Off Ver
    Office 2013
    Posts
    5

    I need to delete any worksheets that are not specified on a list in the first worksheet.

    Hi, I need to figure out how to delete any worksheets in a workbook that are not specified by a list in the A column. I found this code that works if you can specify the worksheets you want to delete beforehand, but I can't figure out how to delete any worksheets that are not on a list. Thanks in advance for any help.

    Sub KillThem()

    Dim ws As Worksheet

    Application.DisplayAlerts = False

    For Each ws In ActiveWorkbook.Worksheets
    Select Case UCase(ws.Name)
    Case "EXCLUDE1", "EXCLUDE2", "EXCLUDE3"
    'do nothing
    Case Else
    ws.Delete
    End Select
    Next

    Application.DisplayAlerts = True

    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: I need to delete any worksheets that are not specified on a list in the first workshee

    Perhaps.
    Please Login or Register  to view this content.
    PS Can you add code tags when posting code?
    Last edited by Norie; 11-13-2015 at 03:28 PM.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: I need to delete any worksheets that are not specified on a list in the first workshee

    Another approach.

    IMPORTANT: You need to specify in the code below the name of the Worksheet that the list is on, so that there is no risk of it being deleted. I commented where you need to put the name.

    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: I need to delete any worksheets that are not specified on a list in the first workshee

    Maybe:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA loop to insert and delete worksheets in a specific sheet within a list
    By supppy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2014, 09:02 PM
  2. [SOLVED] find (criteria from list) delete rows below in another worksheet
    By ufopilot in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2014, 05:38 AM
  3. [SOLVED] Delete rows on 2 different worksheets based on cell value from one worksheet
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-08-2014, 04:14 AM
  4. Delete Worksheets not on list or in named range?
    By Unpackedrope in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-09-2013, 04:12 PM
  5. How to delete a worksheet if it doesn't exist in a list
    By iamrickdeans in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-22-2013, 09:46 AM
  6. insert/delete rows automatically to other worksheets when altering master list on sheet 1
    By whiskeycharlie77 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2012, 08:10 AM
  7. Do while loop to delete worksheets if worksheets are not in the specified list
    By kchm_2000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2011, 03:02 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1