Saturday, December 26, 2015

How Changing color of tabs in Excel using VBA

This code will change all sheet tab color become red


1
2
3
4
5
6
7
8
Sub Sample1()
Dim Sht As Worksheet
For Each Sht In Application.Worksheets
    With Sht.Tab
        .ColorIndex = 3 'red color
    End With
Next Sht
End Sub

Below code use to change sheet tab color become default (no color).


1
2
3
4
5
6
7
8
Sub Sample2()
Dim Sht As Worksheet
For Each Sht In Application.Worksheets
    With Sht.Tab
        .ColorIndex = xlColorIndexNone 'no color
    End With
Next Sht
End Sub

And, below example code use to change tab color for Sheet1 and Sheet3 only.


1
2
3
4
5
6
7
8
Sub Sample3()
Dim SheetName As Variant

SheetName = Array("Sheet1", "Sheet3")
For i = LBound(SheetName) To UBound(SheetName)
    ActiveWorkbook.Sheets(SheetName(i)).Tab.ColorIndex = 3 'red color
Next
End Sub


Download File


No comments :

Post a Comment