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.
Learn more about Allen...
Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Checking All Cell Formatting in VBA.
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:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2127) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Checking All Cell Formatting in VBA.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!