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: Conditional Formatting Based on Date Proximity.

Conditional Formatting Based on Date Proximity

Written by Allen Wyatt (last updated July 22, 2022)
This tip applies to Excel 97, 2000, 2002, and 2003


13

Richard wondered if it was possible, using conditional formatting, to change the color of a cell. For his purposes he wanted a cell to be red if it contains today's date, to be yellow if it contains a date within a week of today, and to be green if it contains a date within two weeks.

You can achieve this type of conditional formatting if you apply a formula. For instance, let's assume that you want to apply the conditional formatting to cell A1. Just follow these steps:

  1. Select cell A1.
  2. Choose Conditional Formatting from the Format menu. Excel displays the Conditional Formatting dialog box. (See Figure 1.)
  3. Figure 1. The Conditional Formatting dialog box.

  4. Set Condition 1 so that Cell Value Is Equal To =TODAY(). Note that you must, in the right-most box, enter an equal sign followed by the TODAY() function.
  5. Click on the Format button. Excel displays the Format Cells dialog box.
  6. Make sure the Patterns tab is selected. (See Figure 2.)
  7. Figure 2. The Patterns tab of the Format Cells dialog box.

  8. Choose the red color you want to use and close the Format Cells dialog box.
  9. Click on the Add button.
  10. Set Condition 2 so that Cell Value Is Between =TODAY()-7 And =TODAY()+7. Note that you must use equal signs in the two right-most boxes, otherwise Excel can't figure out that you are entering a formula.
  11. Click on the Format button. Excel displays the Format Cells dialog box.
  12. Make sure the Patterns tab is selected.
  13. Choose the yellow color you want to use and close the Format Cells dialog box.
  14. Click on the Add button.
  15. Set Condition 3 so that Cell Value Is Between =TODAY()-14 And =TODAY()+14. Again, you must include the equal signs to indicate you are entering formulas.
  16. Click on the Format button. Excel displays the Format Cells dialog box.
  17. Make sure the Patterns tab is selected.
  18. Choose the green color you want to use and close the Format Cells dialog box.
  19. Click on OK.

One important thing to bear in mind with conditional formatting is that criteria are evaluated in the order in which they appear. Once a criteria has been met, then the formatting is applied and other criteria are not tested. It is therefore important to set out the tests in the correct order. If, in the example above, the criteria had been entered in the reverse order, i.e. test for 14 days, then 7 and then 0, it would have only applied the 14 days format even if the date entered was today. In other words, if the date is today then all three of the tests would have been met so you have to be careful of the order in order to get the result you need.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2664) 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: Conditional Formatting Based on Date Proximity.

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

MORE FROM ALLEN

Adding a Background to Your Document

Document backgrounds come in handy if you plan on converting the document to a Web page. Here's how you can add a ...

Discover More

Deleting Worksheet Code in a Macro

When creating an application in VBA for others to use, you might want a way for your VBA code to modify or delete other ...

Discover More

Determining If the End of a Text File Has Been Reached

When writing a macro that processes a text file, you may need to know when the end of the file has been reached. This is ...

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 (menu)

Conditional Formatting with Data Imported from Access

If you want to apply a conditional format to data imported into Excel from Access, you may run into some difficulties ...

Discover More

Conditional Formatting for Errant Phone Numbers

Conditional formatting can be used to draw attention to all sorts of data based upon the criteria you specify. Here's how ...

Discover More

Diagonal Borders in a Conditional Format

Conditional formatting is a great tool for changing how your data looks based on the data itself. Excel won't allow you ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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}] (all 7 characters, in the sequence shown) 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 2 + 2?

2023-01-04 16:02:27

Chris

This is good to know, but I am wanting to know how in a Job Schedule with a calendar to make the day boxes to shade to correlate with the start and finish dates entered for that row...?


2022-05-03 14:21:58

Erin

I have the exact same query as Lee

What about when I don't want to the data to be determined on TODAY's date.
For example,
Column A - Date of Initial Contact
Column B - Date of Final Contact

I want to use conditional formatting to show:
Green - if communication was completed in 4 days or less
Yellow - if communication was completed in 5-7 days
Red - if it took 10 or more days to complete communication.


2021-06-16 09:20:15

Michael

Emnauel Popa - you did not follow what Alan said in the comments below the instructions:

"One important thing to bear in mind with conditional formatting is that criteria are evaluated in the order in which they appear. Once a criteria has been met, then the formatting is applied and other criteria are not tested. It is therefore important to set out the tests in the correct order."

Go back into Conditional Formatting and look for the up and down arrows on the right side - click on each of the conditions and move each of them into the correct order.

1st condition has to be on top of list - to be evaluated FIRST, same for 2nd into 2nd spot etc etc.

Otherwise last will be evaluated first and the others depending on conditions might be ignored.


2021-05-20 04:23:59

Emnauel Popa

This doesn't work, I have tried it and the cell goes only in green, it follows (randomly) only one of the rules.
ANY SUGGESTIONS?


2021-04-13 07:06:45

Bob

G'Day,
I am trying to highlight cells after 17:00 and before 08:00 in order to track after hours work.
Can anyone help.
Cheers,


2020-09-19 19:02:14

John

Hello all!

I am attempting to make a formula for adding certain amounts of days to a date based off of a color scheme.

So if B2 is my accepted date( say 09/19/2020, and the individual stays for 7 days (grey, noted in C2) then I want to add 7 days to B2 date and show it in D2.

So the result would look like:
B2: 09/19/2020
C2: grey box, 7
D2: 09/26/2020

I also have several other days I’d like to add, but I just can’t figure out the formula I’d need


2020-07-02 09:37:27

English Speaker

FYI, 'criteria' is plural. The singular form is 'criterion'. So saying 'a criteria' as you do is nonsense.


2020-01-29 17:58:55

Jordan T

I am trying to highlight dates if they are not within the same calendar year as "NOW" or "TODAY." The proximity in days to the current date does not matter. Can anyone help me?


2019-02-01 10:40:12

Ced W

This tip helped intially but what about formatting a cell based on another cell ...? Like, if the due date in cell A1 is Jan1 but the date completed in cell A2 Jan2 color it red for being past due or green if completed on time ...?


2019-01-14 14:00:42

Archie

Can anyone help me, in conditional formating
Column A and column B
I wanted to condition or put color in column B if B bigger than A

Any one


2018-10-30 21:29:06

Dan Dresner

In a table, I need my entries to each evaluate as whole numbers in order to create a CRC total, in case some of the entries are frax.


2018-05-06 06:43:34

Andrew Ford

Hi,
So I have followed your explanation, with adjustment to my requirements. However, no conditional formatting is being applied.

I have a date, let's say 06/09/2018, they do vary.
I want to format backwards on a 28-day rule, so my rules entered are:
Cell Value equal to =TODAY() -84, format RED, this identifies anything entering 3 months
Cell Value between =TODAY() -84 and =TODAY()-112, format Yellow, this identifies anything between 3 / 4 months
Cell Value between =TODAY() -112 and =TODAY()-140, format Yellow, this identifies anything between 4/ 5 months

Where am I going wrong, I just need to identify dates when they approach a month period.


2018-02-20 11:21:55

Lee

What about when I don't want to the data to be determined on TODAY's date.
For example,
Column A - Date of Initial Contact
Column B - Date of Final Contact

I want to use conditional formatting to show:
Green - if communication was completed in 4 days or less
Yellow - if communication was completed in 5-7 days
Red - if it took 10 or more days to complete communication.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

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.