Conditionally Formatting Cells Containing Dates

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.


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 (11817) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

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. ...


Creating Labels

Using Word to create and print labels is a snap. All you need to do is provide the text you want on the labels, pick a ...

Discover More

Specifying an Order for Page Printing

If a printout of your worksheet requires multiple pages, you may want to specify the order in which Excel prints those ...

Discover More

Finding the Size of Individual Worksheets

Your workbooks can contain many, many worksheets. Which of those worksheets are the largest, however? Here's some ideas ...

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)

Changing Typeface with Conditional Formatting

Conditional formatting can be a great way to modify how the information in your worksheet is displayed. The feature has ...

Discover More

Automatic Lines for Dividing Lists

When preparing a report for others to use, it is not unusual to add a horizontal line between major sections of the ...

Discover More

Detecting Errors in Conditional Formatting Formulas

If an error exists in a formula tucked inside a conditional format, you may never know it is there. There are ways to ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


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}] 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 five more than 8?

2018-01-17 10:24:28

Mark Biegert

Neat trick using the Cell function and the date format. Thanks!

2018-01-17 08:55:18

Jennifer Thomas

Detecting date format by the presence of the d in the code is brilliant! Thanks.

2013-09-30 09:41:01

David Bonin

I tend to look at the values in the cells when searching for a date, particularly prospective dates are reasonably close to now.

Most of my Excel work is business-related and most dates I would deal with are within five years of today. September 30, 2013 has a date value of 41,457. Plus of minus five years gives a range from 39,630 to 43,283. Values in that range are likely dates, at least for me. If in a static formula, I might use 39,000 through 45,000 as the criteria.

On a related note, I sometimes get spreadsheets with broken formats. If I see numbers around 40,000 or so, I take that as a clue those values are dates.

2013-09-30 09:19:47


Micky, it seems that the IsDate function is smart enough to know that even though 12/15/13 is not a date in your system, it could still represent a date. It won't work, for example, for 15/15/2013, which cannot represent a date in any time format.

Technically, the tip asks for the cell *formatting*, not the displayed value (well, reading again, it's a little ambiguous; since I've already typed the rest of the paragraph I'll keep it). The IsDate trick will work if your cell looks like a date, but if the cell is actually formatted in some other format, it could still return True. If this is not what you want, you would need to actually look at the cell formatting. Something along the lines of the following could work (but it's certainly not bullet proof!):

MyIsDate = (rCell.NumberFormat Like "*d*") or (rCell.Numberformat Like "*yy*")

The CELL trick was my first thought. However, the "D" formats also include time-only formats, which is probably not what you want. Using CELL you can find any of the following formats:

m/d/yy, m/d/yy h:mm, mm/dd/yy, d-mmm-yy, dd-mmm-yy, d-mmm, dd-mmm, mmm-yy or mm/dd (note that the "long date" format will NOT be caught by this formula, since it's format is actually "[$-F800]dddd, mmmm dd, yyyy" in my regional settings)

with the following formula:


The caveat to only looking at the number format is, of course, that you could have a non-date (e.g. text) formatted as a date (m/d/yy), and if you *only* look at the formatting, the CELL formula would show TRUE, and the user might not understand why.

Ideally, to cover all your bases, you probably need a solution that looks at both the value AND the format. Or (my default solution) ask yourself, why is it possible for a cell/row/column to contain data of an indeterminite data type, and is it possible to restructure your sheet in such a way that you always know what data type to expect?

2013-09-28 09:44:11

Michael (Micky) Avidan

I'm not able to check foreign formatted dates but the UDF results with TRUE, for both(!) following dates, although in my country (as in most of the world) - 12/15/2013 is NOT really a date.


On the other hand - the CELL functions is OK.

Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)

2013-09-28 06:54:11


The formatting tips are excellent.

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

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.