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.
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
' 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 169
Downloads 66
CodeID
DB ID
ANmarAmdeen
615
Revisions
v1.0
Thursday
August
17
2023