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.
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:
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
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.
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
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:
Best Office Productivity Tools
Supports Office/Excel 2007-2021 and 365 | Available in 44 Languages | Easy to Uninstall Completely
Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need Is Just A Click Away...
Supercharge Your Excel Skills: Experience Efficiency Like Never Before with Kutools for Excel (Full-Featured 30-Day Free Trial)
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! (Full-Featured 30-Day Free Trial)