Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Checking All Cell Formatting in VBA.

Checking All Cell Formatting in VBA

Written by Allen Wyatt (last updated June 1, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

Excel has two different types of formatting that can be applied to cell. The first is explicit formatting. This type of formatting is applied by using the toolbars or by using the Cells option from the Format menu. The second type of formatting is conditional formatting. This type of formatting is applied based on a set of rules that you define.

It is important to understand that these two types of formatting are separate and distinct from each other. For instance, if you explicitly format a cell as bold red, that is the way it appears. If you later apply a conditional format to it, and that format causes the cell to appear in green, that is exactly what is happening—the cell is appearing in green, but it is still formatted as red.

What does this have to do with VBA? If you test the formatting of a cell in VBA, then the formatting you are testing is the explicit formatting. In the above scenario, this means that the test will always indicate that the cell is bold red, and never report that it is green, regardless of what the conditional formatting is doing to the cell. This is because conditional formatting affects the cell's display, not its underlying (explicit) formatting.

The other upshot of all this is that if you want to find out what conditional formatting is being displayed, you may need to recreate all your conditional tests within VBA. This can get rather complex rather quickly. For more information on this topic, there is a great page you can refer to. Check out one of Chip Pearson's pages, here:

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

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8490) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Checking All Cell Formatting in VBA.

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

Swapping Two Strings

Strings are used quite frequently in macros. You may want to swap the contents of two string variables, and you can do so ...

Discover More

Jumping to a Table Row

Need to jump to a particular row in a table? Word provides an easy way to jump to all sorts of things, but it doesn't ...

Discover More

Creating One-time Labels

Need to create a set of labels for a specific purpose? The easiest way is to let Word create a set of blank labels and ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Adding Diagonal Borders

Borders on all sides of a cell are easy to do in Excel. You can also create diagonal borders that run right through the ...

Discover More

Controlling Automatic Formatting of Dates

When you enter something into a cell, Excel tries to figure out if your entry should be formatted in a particular way. ...

Discover More

Wrapping Text in Merged Cells

When you are formatting your worksheet, Excel lets you easily merge adjacent cells together. If you want to wrap the text ...

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 four minus 0?

2019-08-31 07:45:30

Peter McNab

I have found range.DisplayFormat is a handy property that could be included in your tip. Even though the displayed format is set by a condition, it is accessible and can be tested as a property of the cell.
I have found it useful:
to check the current status of a conditional format without evaluating the condition or
when making a snapshot of a sheet I can remove conditional formats but preserve the displayed formats


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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.