How to Use a VBA Macro to Count Worksheet Statuses by Cell Color in Excel
Question details
The user needs to create a VBA macro that counts colored status cells on a Data sheet and writes the totals into specific status columns for each analyst based on configurations from a Database sheet.

- Product
- Excel / WPS Spreadsheet
- Device & OS
- not provided
- Scenario
- Automating the tally of cell backgrounds formatted with specific RGB colors to track analyst workload or project statuses.
- Observed behavior
- The user wants to successfully execute a script that matches header ranges, checks individual rows for assigned interior colors, and accurately populates the corresponding total counts.
Before running the macro, ensure that your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled Developer options in your ribbon settings.
Implement the VBA Macro to Count Cells by Color
Create a custom VBA script that references status definitions from a Database sheet to count colored cells on your Data sheet.
Since native spreadsheet formulas cannot calculate based on cell background color, a custom VBA macro is required. The macro will define the criteria from a master configuration sheet, iterate through the targeted data ranges, and output the sum.
Ensure your worksheet tabs are named correctly, as VBA scripts use precise sheet names to execute.
Press the Alt + F11 keys on your keyboard to open the Microsoft Visual Basic for Applications window.
In the top menu, click 'Insert' and select 'Module' from the dropdown list. This opens a blank text window.
Paste your custom VBA code into the module. Ensure the code is programmed to load status definitions from the 'Database' sheet, read the cell's Interior.Color, and iterate through the analyst rows.
Verify that your VBA script references the correct output headers (e.g., columns AC:AI). The script must match these headers to write the tallied color counts to the appropriate status columns.
Close the VBA editor. Go to the Developer tab on your spreadsheet, click 'Macros', select your newly created script, and click 'Run'.

Use WPS Spreadsheet to Run VBA Macros Seamlessly
WPS Office provides a highly capable Spreadsheet application with excellent VBA macro support, allowing you to run custom scripts, count cells by color, and automate complex data tracking without hassle.
- 1. Install WPS Office: Download and install WPS Office on your computer, making sure to include the VBA module if prompted.
- 2. Open Your Macro-Enabled Workbook: Launch WPS Spreadsheet and open your .xlsm file containing the data and database sheets.
- 3. Run the Automation: Navigate to the 'Developer' tab, click on 'Macros', choose your cell-counting script, and run it to instantly populate your analyst status totals.

Frequently Asked Questions
Can I count colored cells using standard formulas without VBA?
No, standard spreadsheet formulas like COUNTIF or SUMIF do not support criteria based on cell formatting or background colors. Utilizing VBA is the most robust and accurate way to count cells by color.
Why is my VBA macro counting 0 for colored cells?
This commonly happens if the cell's color was applied using Conditional Formatting rather than manual fill. Standard VBA uses 'Interior.Color', but conditionally formatted cells require 'DisplayFormat.Interior.Color' to be counted.
How do I find the correct RGB color code for my VBA script?
Right-click the colored cell, select 'Format Cells', go to the 'Fill' tab, and click 'More Colors'. Under the 'Custom' tab, you will see the Red, Green, and Blue (RGB) values that you can use to configure your VBA macro.




