bottom
Great ExcelTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > ExcelTips Home > Formatting > Conditional Formatting > Conditional Formatting Based on Date Proximity

Conditional Formatting Based on Date Proximity

Summary: Creating conditional formatting to turn cells different colors depending on the values entered. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, and Excel 2003.)

Subscriber Richard Bash 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. (Click here to see a related figure.)
  3. 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.
  4. Click on the Format button. Excel displays the Format Cells dialog box.
  5. Make sure the Patterns tab is selected. (Click here to see a related figure.)
  6. Choose the red color you want to use and close the Format Cells dialog box.
  7. Click on the Add button.
  8. 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.
  9. Click on the Format button. Excel displays the Format Cells dialog box.
  10. Make sure the Patterns tab is selected.
  11. Choose the yellow color you want to use and close the Format Cells dialog box.
  12. Click on the Add button.
  13. 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.
  14. Click on the Format button. Excel displays the Format Cells dialog box.
  15. Make sure the Patterns tab is selected.
  16. Choose the green color you want to use and close the Format Cells dialog box.
  17. Click on OK.

One important thing to bear in mind with conditional formatting is that you can have up to three criteria and different formats that will be applied if those criteria are met. 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.

Tip #2664 applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003


Save Time! You can have this tip (and several hundred just like it) in the ExcelTips annual archives. Imagine having over 400 tips available at your fingertips, in each annual volume.

Helpful Links

Ask an Excel Question
Make a Comment

Tips.Net Home
Vital News Home

ExcelTips FAQ
ExcelTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
ExcelTips Site

 

Great Info!

Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)