+ Reply to Thread
Results 1 to 5 of 5

delete worksheets based on color

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-31-2017
    Location
    usa
    MS-Off Ver
    2013
    Posts
    104

    delete worksheets based on color

    hi, I just need some code to delete all the worksheets in my workbook that have a tab color of red. the macro recorder doesn't work well since my sheet names can change. thx.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: delete worksheets based on color

    Hi xi603
    This should assist...
    Option Explicit
    
    Sub DeleteRedWorkSheetTabs()
    Dim ws As Worksheet
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    For Each ws In Worksheets
        If ws.Tab.Color = vbRed Then
            ws.Delete
        End If
    Next ws
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: delete worksheets based on color

    Sub xi()
      Dim wks As Worksheet
      
      Application.DisplayAlerts = False
      
      For Each wks In Worksheets
        If Worksheets.Count = 1 Then Exit For
        If wks.Tab.Color = vbRed Then wks.Delete
      Next wks
    End Sub
    Entia non sunt multiplicanda sine necessitate

  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: delete worksheets based on color

    FWIW:

    Sub xi603y()
    Dim i As Long, y
    With Application
        .Calculation = xlCalculationManual
        .DisplayAlerts = False
        .ScreenUpdating = False
    End With
    ReDim y(2 To Sheets.Count)
    For i = UBound(y) To LBound(y) Step -1
        If Sheets(i).Tab.ColorIndex = 3 Then Sheets(i).Delete
    Next i
    With Application
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
        .ScreenUpdating = True
    End With
    End Sub

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: delete worksheets based on color

    Glad we could help...Thanks for rep+

+ 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] Delete Row Based on Color
    By trevor2524 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-04-2014, 01:50 PM
  2. delete a row based on color of cell
    By karimretina in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-25-2014, 05:18 AM
  3. [SOLVED] Delete row based on red color font
    By Jhon Mustofa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-02-2014, 10:02 AM
  4. Delete Columns Based On Fill Color
    By jlkirk in forum Excel General
    Replies: 7
    Last Post: 01-28-2013, 02:00 PM
  5. Compare 2 worksheets, delete dupes and group by back fill color using macro
    By jousterlj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2011, 01:50 PM
  6. Delete rows based on fill color
    By schueyisking in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-22-2008, 05:54 AM
  7. Delete Rows Based On Color
    By Tommyweather in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2008, 04:24 AM

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