SheetTabColor

Applies certain color to sheet tab in Excel.
ColorNumber is Excel ColorIndex.
Found a code in https://www.vbatricksntips.com and thought to put it here enhanced.

CodeFunctionName
What is this?

Public

Tested

Imported
Sub SheetTabColor(Optional ColorNumber = 21, Optional Shee = "Active", Optional WB = "This")
    ' Here is VBA code to change color for each tab in a workbook:
    ' Author: Dreams24
    ' Written for VBA Tricks and tips blog
    ' https://www.vbatricksntips.com
    Dim i As Integer
    Dim sht As Worksheet
    If WB = "This" Then WB = ThisWorkbook.Name
    If WB = "Active" Then WB = ActiveWorkbook.Name
    If Shee = "Active" Then Shee = ActiveSheet.Name
    Workbooks(WB).Worksheets(Shee).Tab.ColorIndex = ColorNumber
    ' For i = 1 To ActiveWorkbook.Sheets.Count
    '    Sheets(i).Select
    '    Set sht = ActiveSheet
    '    sht.Tab.ColorIndex = 21
    ' Next i
    ' Sheets(1).Select
    ' MsgBox "Color changed for all tabs.", vbInformation, "Change Tab Color"
End Sub

Optional ColorNumber = 21, Optional Shee = "Active", Optional WB = "This"

Views 218

Downloads 105

CodeID
DB ID