Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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

Excel Productivity Tools

Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial

Kutools for Excel: Save 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial


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 20160930
    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


Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 80% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Rothera Rob · 2 months ago
    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?
  • To post as a guest, your comment is unpublished.
    Q · 2 months ago
    Hello everyone, how do i change tab colour based on a certain value in the column of the multiple sheets? Thanks
  • To post as a guest, your comment is unpublished.
    Victor Nenchev · 3 months ago
    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!
    • To post as a guest, your comment is unpublished.
      skyyang · 3 months ago
      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
  • To post as a guest, your comment is unpublished.
    Victor · 3 months ago
    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!
  • To post as a guest, your comment is unpublished.
    Manuel · 5 months ago
    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.