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

by Allen Wyatt
(last updated August 25, 2012)

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

Remembering Copies to Print

If you routinely need to print more than one copy of a document, you'll love the ideas presented in this tip. There's even a ...

Discover More

Intelligent Title Case

A common editorial need is to change the capitalization used on different words in a selection of text. Word provides a ...

Discover More

Using MPF Graphic Files

There are all sorts of file formats used to store graphics. You might think that one of those formats is the MPF format, ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

MORE EXCELTIPS (MENU)

Conditionally Making a Sound

Need to have a sound played if a certain condition is met? It is rather easy to do if you use a user-defined function to ...

Discover More

Copying Conditional Formatting

Conditional formatting is a great feature in Excel. Here's how you can copy conditional formats from one cell to another in a ...

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

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 for this tip:

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)

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.

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.

Links and Sharing
Share