by Allen Wyatt
(last updated January 17, 2018)
Murali has a large worksheet that contains a variety of different formats. He would like to use conditional formatting to highlight cells that contain dates. He's at a loss, though, as to how to set up the conditional format correctly.
The problem is that Excel doesn't have a worksheet function that returns whether a particular cell contains a date or not. Fortunately, VBA includes such a function, IsDate. This means that you can create a very simple user-defined function to return True or False, depending on whether a cell contains a date:
Function MyIsDate(rCell As Range) MyIsDate = IsDate(rCell) End Function
You can then reference this function in a conditional formatting rule and adjust the formatting based on the results. Remember that this function returns True if the cell contains any date; it does not check for specific dates.
If, for some reason, you don't want to use a macro, you could try this slick little workaround: Set up a conditional formatting rule that relies on the results of a formula. The particular formula you should use is as follows:
The formula returns the format code used for the cell. (In this case the cell is A1. Change this to reflect the cell you are actually testing.) If the first character of the format code is D, then the formula returns True. Excel uses various format codes that begin with D when you format a cell as a date.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11817) applies to Microsoft Excel 2007, 2010, and 2013.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
Conditional formatting is a great tool for changing how your data looks based on the data itself. Excel won't allow you ...Discover More
Conditional formatting does not allow you to change the typeface and font size used in a cell. You can write your own ...Discover More
Excel provides a great conditional formatting capability that allows you to change how a cell appears based on critiera ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.