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):
Group worksheets in Excel makes it easier to manage a big workbook. This feature allows you to treat multiple worksheets as one, helping you perform identical tasks like formatting or data entry across several sheets…
If you need to keep This quick guide explains what Excel circular references are and why you should be careful when using them. You’ll also learn how to check for, find, and remove circular references in Excel worksheet.a circular reference, it will show you how to turn on and use circular formulas safely
You tried to enter a formula in your Excel sheet, but it’s not working. Instead, Excel is showing you a message about a circular reference. Is that why you’re here? 🙂
Thousands of people run into this issue every day because they accidentally make an Excel formula try to calculate its own cell. When this happens, Excel gives the following error message:
Understand the basic Different between Excel Online vs Excel Desktop. Excel Online is like a simpler version of Excel that you can use in your web browser. It has most of the important features you need, but it doesn’t have advanced things like macros. This article dives into the differences between Excel Online and the excel Desktop version to help you understand what each one is good at and where they fall short.
When creating a formula in Excel, many people get confused by the $ symbol in cell references. But it’s actually very simple. The dollar sign in an Excel cell reference tells Excel whether to keep the reference the same or allow it to change when you copy the formula to other cells. This guide will explain how it works and why it’s helpful.
Understanding Excel cell references is really important. Knowing the difference between absolute, relative, and mixed references will help you get the most out of Excel formulas and functions.
Delta Symbol in Excel The Greek Capital Alphabet letter Delta (▲) and is commonly discussed topic in Excel. This is being used for various purposes i.e. changes in quantity, insert the symbol in excel etc….
MAX function is used to get the largest number in range or list of values. MAX function has one required argument i.e. number1
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 🙂