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.
Written by Allen Wyatt (last updated June 1, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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:
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.
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!
As you are formatting a worksheet, Excel allows you to easily add borders to cells. Adding rounded corners to cells is a ...
Discover MoreWant to repeat cell contents over and over again within a single cell? Excel provides two ways you can duplicate the content.
Discover MoreIf your workbooks are shared and used by a number of different people, you may end up with some formatting in those ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments