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

Inserting a File

Need to combine several files into a single document? You can do it by inserting one file into another, as outlined in ...

Discover More

Rotating a Drawing Object

You can add all sorts of drawing objects to a document. Once placed, you can then rotate them to your heart's content. ...

Discover More

Searching for Styles

If you use styles to format your text, you can later search for words and phrases that are formatted using various ...

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 (ribbon)

Changing the Default Vertical Alignment

By default, Excel vertically aligns cell contents to the bottom of cells. If you prefer a different default alignment, ...

Discover More

Stopping Fractions from Reducing

Enter a fraction into Excel, and you may be surprised that the program reduces the faction to its simplest form. If you ...

Discover More

Setting Cell Color Based on Numeric Values

Excel allows you to specify colors for the interior of cells in your worksheet. If you want those colors to be set ...

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 1 + 1?

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.