Conditionally Formatting Cells Containing Dates

by Allen Wyatt
(last updated August 14, 2017)


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.

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


Calculating Form Fields

Form fields allow you to create (you guessed it) forms. Here is a description of how you can force Word to calculate the ...

Discover More

Selecting Sentences

Need to select an entire sentence at once? You can do so by creating a short macro that does the task for you, or you can ...

Discover More

Working while a Macro is Running

If you have a macro that takes a long time to process a workbook, you might want to continue working in Excel while the macro ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

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

Discover More

Protecting Your Conditional Formatting Rules

If you have conditional formatting applied in a worksheet, the formulas in those formats may not be as secure as you would ...

Discover More

Finding Cells that Use Conditional Formatting

Conditional Formatting is a great boon to effectively displaying the information in your worksheets. If you want to easily ...

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 8 - 2?

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.