Have you ever got into situation in office where you need to count the cells in Excel sheet with specific color? If yes then you can use following code which counts the number of cells with specific color (here it is yellow) and put the count in cell
It is worth to mention that the above code does not count the cells where colors are coming through conditional formatting. You can use DisplayFormat.Interior.Color to get the conditional formatting colors (DisplayFormat.Interior.Color works only on Excel 2010 or above) or read thisย post
Public Function CountColorCells(rng As Range) As Long
'Variable declaration
Dim lColorCounter As Long
Dim rngCell As Range
'loop throught each cell in the range
For Each rngCell In rng
'Checking Yellor color
If Cells(rngCell.Row, rngCell.Column).Interior.Color = RGB(255, 255, 0) Then
lColorCounter = lColorCounter + 1
End If
Next
'Return the value
CountColorCells = lColorCounter
End Function
To use this code in your Excel file, follow below steps:
Here I have counted the cells with yellow color. You can change RGB (#,#,#) code to count other colors. You can find RGB codes of any color using following steps
Thatโs all, in the โColorโ dialog box, you can view the RGB (Red, Green, Blue) codes of the color
If you are look for a code to sum the cells based on itโs color then you can read thisย post.
In this tutorial, I will show you threeย ways to count colored cells in Excel (with and without VBA):
Want to learn how to unprotect Excel worksheet? Follow this simple guide to master this important skill in Excel. You can protect an Excel worksheet with or without a password. This helps keep your data…
Video: How to Hide Worksheet in Excel? Hide Sheet in Excel When I was creating an excel dashboard, there were multiple sheets which I used for calculation purpose and never wanted anybody to make any…
How to Insert Symbol in Excel? I came across many queries regarding inserting special symbols in Excel. Here we are guiding how you may do this quickly in excel. Follow these steps and you may…
This tutorial shows how to quickly change CSV files into Excel in any version, from 365 to 2007, without common problems.
There are two main ways to move a CSV file to Excel: by opening it directly or by importing it as external data. This article gives step-by-step instructions for both methods, explains their pros and cons, and highlights potential problems with tips to fix them
This guide shows how to use the nested IF function in Excel to check several conditions. You will also learn about other functions that can be to use than a nested formula.
When you want to make decisions in Excel, you often use an IF formula. It checks if something is true, then gives one result if it is and another result if it isnโt. If you need to check more than one thing, you can put many IFs inside each other.
Although using multiple IFs is common, itโs not the only way to check several conditions in Excel. This guide will introduce you to some easier and useful alternatives.
Scroll Lock in Excel can make scrolling, selecting cells, checking formulas, entering data, and recording macros harder. So, you might need to turn it off to work normally. In this article, weโll show you how…
It doesn’t work with conditional formatting because the cell color does not really change
This code does not work with conditional formatting however we made it work. So please read below article to count colored cells with conditional formatting.
Count Colored Cells with Conditional Formatting
Hope you like the article. Please comment if you liked the solution. ๐
Happy Reading!
Great tips! I always struggled with counting colored cells in Excel, but your step-by-step guide made it so easy to follow. Thanks for sharing!
Thanks.
Great tips! I never knew counting colored cells could be so straightforward with Excel. Thanks for breaking it down step by step!
Thank you for the feedback. Keep learning ๐
Thank you for this detailed guide! Counting colored cells in Excel always seemed tricky to me, but your step-by-step instructions made it much easier to understand. I can’t wait to try it out in my own spreadsheets!
Thank you so much for your feedback. Keep learning ๐