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.
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.
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!!!
![]()
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
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
Glad we could help...Thanks for rep+![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks