Counting Colors from Conditional Formats

Written by Allen Wyatt (last updated May 4, 2024)
This tip applies to Excel 97, 2000, 2002, and 2003


Ronald has a worksheet that utilizes conditional formatting. The conditions result in the cells being different colors. He wants to count the number of cells that are red in the worksheet. He knows how to create a macro that will examine the cell color and do a count if a cell is formatted directly as red, but the macro won't work with cells that are conditionally formatted. Ronald wants to know if there is a way to count these conditionally red cells, as well.

You cannot directly check in a macro what the color of a cell is based on a conditional format. There are ways you can work around this with a macro, but it is not for the faint-of-heart. The following page on Chip Pearson's site demonstrates the difficulty in determining conditional colors:

http://www.cpearson.com/excel/CFColors.htm

Given the difficulty of the task, it may just be easier to recreate the conditions within the macro, and then see which cells meet these conditions. The result is that you count cells matching conditions rather than count cells that are colored red as a result of those conditions. This should yield the same count of cells, but is much easier to handle programmatically.

Of course, the only caveat to this solution is that you will need to keep the conditions in the macro and the conditions in the conditional formats in sync with each other. If you change one and fail to change the other, then you won't get the desired results.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2873) applies to Microsoft Excel 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Inserting the Edit Time

One of the things that Word keeps track of is how long, in minutes, you've been editing your current document. This ...

Discover More

Managing Comments

If you frequently add comments to cells in a worksheet, Excel provides a variety of tools you can use to manage those ...

Discover More

Counting Consecutive Negative Numbers

If you have a range of values that can be either positive or negative, you might wonder how to determine the largest ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Conditionally Formatting for Multiple Date Comparisons

When you compare dates in a conditional formatting rule, you need to be careful how you put your comparisons together. Do ...

Discover More

Diagonal Borders in a Conditional Format

Conditional formatting is a great tool for changing how your data looks based on the data itself. Excel won't allow you ...

Discover More

Conditionally Making a Sound

Need to have a sound played if a certain condition is met? It is rather easy to do if you use a user-defined function to ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is six more than 5?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.