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

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

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


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.
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
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.
    Brage · 3 months ago
    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
  • To post as a guest, your comment is unpublished.
    Rothera Rob · 8 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 · 9 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 · 9 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 · 9 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 · 9 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 · 1 years 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.
  • To post as a guest, your comment is unpublished.
    Ian · 1 years ago
    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.
  • To post as a guest, your comment is unpublished.
    Ahmed · 1 years ago
    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.
  • To post as a guest, your comment is unpublished.
    Jen Langston · 1 years ago
    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.
  • To post as a guest, your comment is unpublished.
    Shannon · 1 years ago
    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?
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      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!
  • To post as a guest, your comment is unpublished.
    Rich · 1 years ago
    how can I change a tab color depending on weather a range of cells have text in them
  • To post as a guest, your comment is unpublished.
    Faiz Ibn Uvaiz · 2 years ago
    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.
    • To post as a guest, your comment is unpublished.
      Michael Black · 2 years ago
      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.