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):
This guide explains the basics of Excel’s Advanced Filter and shows you how to use it to find records that match one or more complicated conditions.
If you’ve read our previous guide, you know that Excel’s regular filter offers different options for filtering text, numbers, and dates. These options work well for many situations, but not all. When the regular filter isn’t enough, you can use the Advanced Filter to set up custom criteria that fit your exact needs.
Excel’s Advanced Filter is especially useful for finding data based on two or more complex conditions. For example, you can use it to find matches and differences between two columns, filter rows that match another list, or find exact matches with the same uppercase and lowercase letters.
Advanced Filter is available in all Excel versions from 365 to 2003. Click the links below to learn more.
MATCH function performs lookup for a value in a range and returns its position sequence number as output. It has two required and one optional arguments
LOWER function is used for changing the format of any text or string to LOWER case.
This tutorial shows you three easy ways to add hyperlinks in Excel. You will learn how to insert, change, and remove hyperlinks in your worksheets. It also explains how to fix links that don’t work.
Hyperlinks are often used on the internet to move between websites. In Excel, you can create links like that too. You can make a link to another cell, a different sheet, or even another workbook. You can also link to open a new Excel file or start an email message. This guide will show you how to do all of this in Excel 2016, 2013, 2010, and older versions.
How to Create a Pivot Table? Pivot Tables in excel is backbone of data analysis in excel. If you want to perform various analysis in excel, then I would suggest, learn this amazing excel feature…
AVERAGE function is used to get the average of numbers. Function applies formula i.e. average = Sum of all values / (Divided by) number of items.
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!