Note: The other languages of the website are Google-translated. Back to English
English English

How to change sheet tab color based on cell value?

Normally, you can change the tab color easily and quickly in Excel, but, have you ever tried to change the tab color based on cell value in a worksheet? If you are intrested in this task, I will talk about some codes for you to color the sheet tab based on a specific cell value in Excel.

Change one sheet tab color based on cell value with VBA code

Change multiple sheet tabs based on cell value with VBA code


arrow blue right bubble Change one sheet tab color based on cell value with VBA code

For example, I want the current sheet tab color will be green if the cell value in A1 is the text “TRUE”, the tab color will be red if the text in A1 is “FALSE”, and the tab color will be blue if the value in cell A1 is any other text as following screenshot shown:

doc color sheet by value 1

1. Right click the sheet tab that you want to change its color based on the data in cell A1, and then choose View Code from the context menu.

2. In the Microsoft Visual Basic for Applications window, copy and paste the below VBA code into the Module window.

VBA code: Change one sheet tab color based on cell value:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
    If Target.Address = "$A$1" Then
        Select Case Target.Value
        Case "False"
            Me.Tab.Color = vbRed
        Case "True"
            Me.Tab.Color = vbGreen
        Case Else
            Me.Tab.Color = vbBlue
        End Select
    End If
End Sub

doc color sheet by value 2

Note: In the above code, A1 is the cell reference which you want to color the tab based on, “True”, “False” are the text you need, you can change them to your need, and you can change the color in the code as you need.

3. Then save and close this code window, now, when you enter the text “True” in cell A1, the current tab color will become green, and when you enter the text “False” in cell A1, the tab color will become red, and if other text is entered into the cell A1, the tab color will become blue automatically.


arrow blue right bubble Change multiple sheet tabs based on cell value with VBA code

If you need to change multiple sheet tabs color based on a cell value, here is also a code may help you, please do as follows:

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window, in the opened window, double click ThisWorkbook under the VBAProject section, then copy and paste the below code into the blank Module:

VBA code: Change multiple sheet tabs based on cell value:

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  'Updateby Extendoffice 20160930
  Select Case Sheets("Master").Range("A1").Value
         Case "KTE"
             Sheets("Sheet1").Tab.Color = vbRed
         Case "KTO"
             Sheets("Sheet2").Tab.Color = vbGreen
         Case "KTW"
             Sheets("Sheet3").Tab.Color = vbBlue
         End Select
End Sub

doc color sheet by value 3

Note: In the above code, A1 and Master are the cell and worksheet which you want to color the tab based on, Sheet1, Sheet2, Sheet3 are the worksheets that you want to color the tabs. KTE, KTW, KTO are the cell values in A1 that you want to color the tabs based on, you can change the references and colors in the code as you need.

2. Then save and close this code window, now, when you enter the text KTE in cell A1 of the Master sheet, Sheet1 tab will be colored in red, when you enter KTO in cell A1,the Sheet2 will be colored in green, and when you enter KTW in cell A1, the Sheet3 will be colored in blue, see screenshot:

doc color sheet by value 4


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Comments (23)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Dear Sir.
kindly help me how to change the sheet tab color based on date/day.

for Eg:-
if sheet No 1 is Sunday then - sheet tab 'RED'
if sheet No 2 is Monday then - sheet tab 'Green'
if sheet No 3 is Tuesday then - sheet tab 'Green'
if sheet No 4 is Wednesday then - sheet tab 'Green'
if sheet No 5 is Thursday then - sheet tab 'Green'
if sheet No 6 is Friday then - sheet tab 'Green'
if sheet No 7 is Saturday then - sheet tab 'Green'

kindly help me for the above excel issue.

Thanks and regards
Faiz Ibn Uvaiz P.
This comment was minimized by the moderator on the site
Your description is a little vague as to what you are actually trying to do. If the workbook is only for a week then color the tabs. If the duration is longer than a week, then the solution is a little more complex. Until you detail the problem, there are several solutions that are available. I, and many people, will not spend our time coding 2,000 solutions for you for free. But you detail the problem we might provide 1 solution.
This comment was minimized by the moderator on the site
how can I change a tab color depending on weather a range of cells have text in them
This comment was minimized by the moderator on the site
The formula is working for 'True' - sheet tab is RED, so that is great but if I change it from 'True' to 'False' I want the sheet tab to have 'no color'. What is the formula for no color on the sheet tab if 'True' is not selected? Also if I want the formula to be for a group of cells eg. A1:A30 what is the code I use?
This comment was minimized by the moderator on the site
Hello,Shannon:
The following VBA code may do you a favor, please try it:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
Set xRg = Intersect(Target, Range("A1:A30"))
If xRg Is Nothing Then Exit Sub
Select Case Target.Value
Case "True"
Me.Tab.Color = vbRed
Case "False"
Me.Tab.Color = False
End Select
End Sub

Hope this can help you!
This comment was minimized by the moderator on the site
Is there a way to get the tab color to change based on the following: I have a master tab where rows 3-7 are colored blue and will correspond with corresponding tabs 3-7 (which are named based on cell values in the master in those rows) that i would like colored blue. Then rows 8-12 are colored green and also correspond to tabs 8-12 and so on.
This comment was minimized by the moderator on the site
That was one awesome trick.
I linked the tab color based on value of cell A1 (<>0 RED and =0 Green), however, the macro executes only if i select A1 , the press F2 and then press enter. Without doing this although the color of the tab ( based on its value ) should be , say Red, but stays green.
I am using excel 2007.
This comment was minimized by the moderator on the site
Is it possible to make this work when cell A1 can have all 3 answers on separate lines within the cell? That is KTE, KTO and KTW are all present in the cell as it allows multiple selections from a drop down list.
This comment was minimized by the moderator on the site
I'm trying to use that code and apply it to a check box, so when I check the box, the color changes, if I uncheck it, it changes back (i got true=green, false=red ,else=red). But when I check and uncheck it throws an error 'object needed'


Private Sub CheckBox1_Click()
_____If Target.Address = "$e$5" Then 'error here
__________Select Case Target.Value
__________Case "False"
_______________Me.Tab.Color = vbRed
__________Case "True"
_______________Me.Tab.Color = vbGreen
__________Case Else
_______________Me.Tab.Color = vbRed
__________End Select
_____End If
End Sub

I copied and pasted it to see it run and then adjust it to my need but I would not find a way to make it run.
This comment was minimized by the moderator on the site
Dear colleagues,
Kindly ask for help. I need to change the sheet tab color based on value in format [h]:mm. For example if the value is below 20:00 - red, >20:00 green.
Thanks and regards!
This comment was minimized by the moderator on the site
Dear colleagues,
Kindly ask for help. I need to change the sheet tab color based on value in format [h]:mm. For example if the value is below 20:00 - red, >20:00 green.
Thanks and regards!
This comment was minimized by the moderator on the site
Hello, Victor,
The below VBA code can sovle your problem, please try, hope it can help you!

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xStr As String
Dim xSN As String
Dim xDate As String
Dim xAddress As String
Dim xArr() As String
Dim xI1 As Integer
Dim xSM As String
xDate = "20:00"
xAddress = "$A$1"
If Target.Address <> xAddress Then Exit Sub
xStr = Target.Text
xArr = Split(xStr, ":")
If (UBound(xArr) - LBound(xArr) + 1) > 2 Then Exit Sub
xI1 = Int(xArr(0))
If (Len(xArr(0)) - 2) < 1 Then
If xI1 > 23 Then Exit Sub
Else
Exit Sub
End If
xSM = xArr(1)
On Error GoTo Err01
If (Len(xSM) - 2) <> 0 Then Exit Sub
If Int(Left(xSM, 1)) > 5 Then Exit Sub
If Int(Right(xSM, 1)) > 10 Then Exit Sub
If xI1 >= 20 Then
Me.Tab.Color = vbGreen
Else
Me.Tab.Color = vbRed
End If
Err01:
End Sub
This comment was minimized by the moderator on the site
Dear Skyyang,
Sorry for the too late feedback. This formula is working when i manually change the value in the cell. But that wasn't what i need.
The cell value is result of a formula from difference sheets. For example, this is the formula in the cell "O13-'520'!AD3". This means that the value in this cell is changing depending from the value the deferent cell in deferent sheet. What i need is the sheet color to be changed automatically when the value in cell "O13-'520'!AD3" is changed, when the value in the cell "O13-'520'!AD3" is below 05:00 - red, >20:00 green, between 05:00 and 20:00 brown.
Thank you in advance and best regards!
This comment was minimized by the moderator on the site
Hello everyone, how do i change tab colour based on a certain value in the column of the multiple sheets? Thanks
This comment was minimized by the moderator on the site
How would you link the tab to a value in a different tab. In my example I have one tab with all the information that filters out to various tabs automatically. However each tab will read green or red, depending on whether there is a bAlance outstanding on the master tab. Can this be done using this code and if so, where do I write the link to the master sheet within this code?
This comment was minimized by the moderator on the site
Hello,

Never done code in excel before. I need a code that do what this code do, but I need another parameter.

So what I need is:

If cell value is not 0, and/or if some other cell has numbers in it, using count, then change color to red

If cell value is 0 and those other cells are empty, using count, then change color to green
This comment was minimized by the moderator on the site
Hello, Trying to have tab colour change based on value on a seperate sheet called Tracking here is what I tried but it does not seem to be working. Thanks




Private Sub Worksheet_Change(ByVal Target As Range)

'Updateby Extendoffice 20160930

If Target.Address = "Tracking!$C$2" Then

Select Case Target.Value

Case "ip"

Me.Tab.Color = vbRed

Case "w"

Me.Tab.Color = vbYellow

Case "c"

Me.Tab.Color = vbGreen

Case Else

Me.Tab.Color = vbBlue

End Select

End If

End Sub
This comment was minimized by the moderator on the site
Hello, Brad,
To make the code run correctly, you should not insert the sheet name into the code, please apple the following code:(click the sheet name you want to run this code, and then right clik the sheet name, and choose View Code, then paste the code into the module)

Private Sub Worksheet_Change(ByVal Target As Range)

'Updateby Extendoffice 20160930

If Target.Address = "$C$2" Then

Select Case Target.Value

Case "ip"

Me.Tab.Color = vbRed

Case "w"

Me.Tab.Color = vbYellow

Case "c"

Me.Tab.Color = vbGreen

Case Else

Me.Tab.Color = vbBlue

End Select

End If

End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Im looking to change to color of the tab based off one of 2 outcomes of a formula I have a formula of=IF((AND(AA1="Occupied",AA2="Occupied",AA3="Occupied",AA4="Occupied")),"Occupied","Vacant")
I need the tab to be red if "Occupied" and green if "Vacant". However the code above in the main post doesn't recognize the output of the If Than
This comment was minimized by the moderator on the site
Hello ,
I require some help
I need to change the sheet tab color only if in a certain range of cells, has today's date
Say for example,
Column L has some dates in the format (13-May-22)
One of the cell value is today's date, then the tab sheet color should change to red
Please help
Thank you in advance
This comment was minimized by the moderator on the site
I would like my tab to change color if any cell in column O or column P has a value in it. Is this possible?

Thank you!
This comment was minimized by the moderator on the site
I want to set the sheet tab color based on the color of cell j4 in each sheet. There are 18+ Tabs and want to update the tab colors when the workbook is opened. If I can’t update when opened I can run the macro after the teams update the sheets.
This comment was minimized by the moderator on the site
Hello, wood
To solve your problem, please apply the below code: (Note: Copy and paste the below code into the ThisWorkbook code mode)
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Call SetSheetColor
End Sub

Private Sub Workbook_Open()
Call SetSheetColor
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Call SetSheetColor
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Call SetSheetColor
End Sub

Sub SetSheetColor()
Dim xWShs As Sheets
Dim xRg As Range
Dim xFNum As Integer
Dim xSh As Worksheet
On Error Resume Next
Set xWShs = Application.ActiveWorkbook.Sheets
For xFNum = 1 To xWShs.Count
    Set xSh = xWShs.Item(xFNum)
    Set xRg = xSh.Range("J4")
    xSh.Tab.Color = xRg.Interior.Color
Next
End Sub


https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-color-sheet.png

Please have a try, hope it can help you!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations