+ Reply to Thread
Results 1 to 6 of 6

Macro to delete Sheets with specific name content

  1. #1
    Registered User
    Join Date
    10-20-2010
    Location
    costa rica
    MS-Off Ver
    Office365
    Posts
    28

    Macro to delete Sheets with specific name content

    Hi Guys,

    I have a excel with the following sheets :
    • Menu
    • Worksheet
    • Filtered
    • 601 01
    • 601 02
    • 601 01-Duplicates
    • 601 02-Duplicates

    The sheets with numbers could be more and at the same time could have the same sheet but with -Duplications at the end :

    Example:
    • 601 01
    • 601 02
    • 601 03
    • 601 04
    • 601 05
    • 601 01-Duplicates
    • 601 02-Duplicates
    • 601 03-Duplicates
    • 601 04-Duplicates
    • 601 05-Duplicates


    But in this case I need to delete all the sheets with the exception of :

    Menu
    Worksheet
    Filtered
    601 01-Duplicates
    601 02-Duplicates


    I have this code: But I'm not able to delete the sheets I want. Could you please provide me any suggestion ?


    Sub DeleteSheets1()
    Dim xWs As Worksheet
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    For Each xWs In Application.ActiveWorkbook.Worksheets
    If xWs.Name <> "Menu" And xWs.Name <> "Worksheet" And xWs.Name <> "Filtered" And xWs.Name = "*-Duplicates " Then
    xWs.Delete
    End If
    Next
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub



    Attached the excel file

    Book1.xlsm

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Macro to delete Sheets with specific name content

    Try it like this - unclear if you want to keep -Duplicates or delete them.... this code keeps them

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Macro to delete Sheets with specific name content

    This would be another possibility.
    Easy to adjust for changing needs.

    Please Login or Register  to view this content.
    Experience trumps academics every day of the week and twice on Sunday.

  4. #4
    Registered User
    Join Date
    10-20-2010
    Location
    costa rica
    MS-Off Ver
    Office365
    Posts
    28

    Re: Macro to delete Sheets with specific name content

    works perfectly . Thanks a lot !!

  5. #5
    Registered User
    Join Date
    10-20-2010
    Location
    costa rica
    MS-Off Ver
    Office365
    Posts
    28

    Re: Macro to delete Sheets with specific name content

    Quote Originally Posted by Bernie Deitrick View Post
    Try it like this - unclear if you want to keep -Duplicates or delete them.... this code keeps them

    Please Login or Register  to view this content.
    Thanks a lot is perfect

  6. #6
    Registered User
    Join Date
    10-20-2010
    Location
    costa rica
    MS-Off Ver
    Office365
    Posts
    28

    Re: Macro to delete Sheets with specific name content

    Quote Originally Posted by jolivanes View Post
    This would be another possibility.
    Easy to adjust for changing needs.

    Please Login or Register  to view this content.
    Love the suggestion too . Thanks a lot

+ 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. [SOLVED] Sort by specific column & delete rows based on content
    By axtryo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-21-2018, 01:49 AM
  2. [SOLVED] Macro to open multiple workbooks and delete specific sheets
    By JPSIMMON in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-03-2015, 07:39 PM
  3. [SOLVED] Macro to delete sheets in a workbook if sheet does not contain specific word
    By elgato74 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-26-2014, 02:08 PM
  4. [SOLVED] Global Macro to delete row based on specific cell content expect for row 1
    By intercooler in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-10-2012, 07:13 PM
  5. [SOLVED] Macro to delete rows if any cell contains specific content
    By adayoan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-31-2012, 07:11 PM
  6. scan through sheets to count cells with specific content
    By ossa in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-06-2012, 12:08 PM
  7. Delete entire row from A to F if cell A has specific content
    By vtech in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-02-2010, 06:01 AM

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