Forum Discussion
burningshield
Oct 17, 2025Copper Contributor
Excel: Count cells with specific value + colour
Hi there, I would like to be able to count the number of cells that contain a specific value and are shaded a specific colour. This is for a rota spreadsheet that will be tallying the total number ...
burningshield
Oct 22, 2025Copper Contributor
Hi Lorenzo,
Thank you so much for your helpful suggestions. I'm definitely not a VBA expert either! I tried your option 1 and this seems to work well with any cell colour shading. However, I couldn't get option 2 to work for some reason, even though I specified the exact HEX code in the code, and highlighted the cells with this in the rota. It didn't seem to pick this up for some reason and I'm not sure what I may be doing wrong.
Lorenzo
Oct 27, 2025Silver Contributor
Hi
Apologies for the delay (I didn't get a notification re. your reply)
For Option2, try the following...
Instead of using the Hex value you see in the dialog box :
- Note the Red, Green and Blue values
- In the VBA code change line:
If Hex(CStr(cell.Interior.Color)) = "xxxxxx" Thenwith:
If Hex(CStr(cell.Interior.Color)) = Hex(RGB(0, 176, 80)) Thenreplacing 0, 176, 80 with the Red, Green and Blue values you noted