How to Change Excel Worksheet Tab Color Based on a Cell Value
Question details
Automatically update the color of worksheet tabs across a workbook based on a specific cell's text value (e.g., 'Correct' or 'Incorrect').
- Product
- Microsoft Excel / WPS Spreadsheet
- Device & OS
- not provided
- Scenario
- A user has a workbook with multiple sheets and wants the tab color of each sheet to turn green if cell G28 says 'Correct', red if it says 'Incorrect', and have no color if the cell is blank. The color needs to update continuously as the cell value changes.
- Observed behavior
- Currently, manual tab coloring is static. The goal is to apply a dynamic VBA macro event that detects value changes in cell G28 and automatically applies the appropriate ColorIndex to the worksheet tab.
Ensure that the Developer tab is enabled in your spreadsheet ribbon and that macro security settings allow VBA code to run, as this solution relies on a custom macro.
Use the Workbook_SheetChange VBA Event
Add a VBA macro to the ThisWorkbook module to monitor cell changes globally and update tab colors dynamically.
By placing the code in the 'ThisWorkbook' module rather than individual sheets, the macro will apply to all worksheets in your file simultaneously.
This specific script uses the Workbook_SheetChange event, which triggers whenever a cell value is manually edited or modified.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) window.
In the Project Explorer pane on the left side, double-click on 'ThisWorkbook'.
Select 'Workbook' from the left dropdown above the code window and 'SheetChange' from the right dropdown. Paste the logic to evaluate the cell: Use an If or Select Case statement to check if Sh.Range("G28").Value is 'Correct', 'Incorrect', or blank.
Set the Sh.Tab.ColorIndex property based on the value. Use 4 for green ('Correct'), 3 for red ('Incorrect'), and xlColorIndexNone for blank.
Close the VBA editor and save your file as an Excel Macro-Enabled Workbook (*.xlsm) so the code remains active.
Run VBA Macros Seamlessly in WPS Spreadsheet
WPS Office fully supports Visual Basic for Applications (VBA), allowing you to write, edit, and run macros to automate tasks like changing tab colors based on cell values without any extra configuration.
- 1. Open Your File in WPS: Launch WPS Spreadsheet and open your existing workbook.
- 2. Open the Developer Tab: Navigate to the Developer tab on the top ribbon and click on 'Visual Basic', or press ALT + F11.
- 3. Add the Code: Double-click 'ThisWorkbook' in the Project Explorer and paste your VBA event code.
- 4. Save the Macro File: Save your document as a Macro-Enabled Workbook (.xlsm) to ensure your automated tab colors continue working.

Frequently Asked Questions
Why isn't my tab color updating when the cell formula result changes?
The 'Worksheet_Change' or 'Workbook_SheetChange' events are only triggered by direct manual data entry or external links. If your target cell changes its value because of a formula calculation (like an IFS function), you need to use the 'Workbook_SheetCalculate' event instead.
How do I find the correct ColorIndex number for VBA?
Excel VBA uses a specific set of numbers for its standard color palette. For example, 3 is Red, 4 is Green, 5 is Blue, and 6 is Yellow. Alternatively, you can use the 'Sh.Tab.Color = RGB(255, 0, 0)' property for precise custom colors.
Can I apply this macro to just one specific sheet instead of all 10 sheets?
Yes. Instead of placing the code in 'ThisWorkbook', right-click the specific worksheet tab, select 'View Code', and insert your code using the standard 'Worksheet_Change' event.




