excel2007.Tips.Net Welcome toExcel2007.Tips.Net

Helpful Links

Excel 2007 Home
Tips.Net Home

Ask a Question
Make a Comment

Cleaning Tips
Legal Tips
Pest Tips
Pet Tips

Newest Tips

Changing a Link's Source

Using Conditional Formatting to Shade Rows

Editing by Moving and Copying

Making Sure Duplicate Names Aren't Entered

Applying a Conditional Format to a Full Row

Hiding Worksheet Tabs

Making Cells Flash

 

Conditional Colors based on Dates

Summary: Conditional formatting can be used to draw your attention to certain cells based on what is within those cells. This tip explains how you can use conditional formatting to change the color of cells based upon how close a particular date is to today's date.

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. With the Home tab of the ribbon displayed, click the Conditional Formatting option in the Styles group. Excel displays a palette of options related to conditional formatting.
  3. Choose Manage Rules. Excel displays the Conditional Formatting Rules Manager dialog box. (Click here to see a related figure.)
  4. 4.` Click New Rule. Excel displays the New Formatting Rule dialog box.
  5. In the Select a Rule Type area at the top of the dialog box, choose Format Only Cells that Contain. (Click here to see a related figure.)
  6. In the Edit the Rule Description area, change the second drop-down list to Equal To.
  7. In the area just to the right of the drop-down list enter the formula =TODAY(). Note that you must, in the right-most box, enter an equal sign followed by the TODAY() function.
  8. Click Format to display the Format Cells dialog box and display the Fill tab.
  9. Specify that you want the color of the cell to be red.
  10. Click OK to dismiss the Format Cells dialog box. The formatting you specified in step 7 should now appear in the preview area for the rule.
  11. Click OK. The New Formatting Rule dialog box disappears and the newly defined rule is shown in the Conditional Formatting Rules Manager dialog box.
  12. 12.` Click New Rule. Excel again displays the New Formatting Rule dialog box.
  13. In the Select a Rule Type area at the top of the dialog box, choose Format Only Cells that Contain.
  14. In the Edit the Rule Description area, change the second drop-down list to Is Between.
  15. In the areas just to the right of the drop-down list enter the formulas =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.
  16. Click Format to display the Format Cells dialog box and display the Fill tab.
  17. Specify that you want the color of the cell to be yellow.
  18. Click OK to dismiss the Format Cells dialog box. The formatting you specified in step 7 should now appear in the preview area for the rule.
  19. Click OK. The New Formatting Rule dialog box disappears and the newly defined rule is shown in the Conditional Formatting Rules Manager dialog box.
  20. 20.` Click New Rule. Excel again displays the New Formatting Rule dialog box.
  21. In the Select a Rule Type area at the top of the dialog box, choose Format Only Cells that Contain.
  22. In the Edit the Rule Description area, change the second drop-down list to Is Between.
  23. In the areas just to the right of the drop-down list enter the formulas =TODAY()-14 and =TODAY()+14. 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.
  24. Click Format to display the Format Cells dialog box and display the Fill tab.
  25. Specify that you want the color of the cell to be green.
  26. Click OK to dismiss the Format Cells dialog box. The formatting you specified in step 7 should now appear in the preview area for the rule.
  27. Click OK. The New Formatting Rule dialog box disappears and the newly defined rule is shown in the Conditional Formatting Rules Manager dialog box.
  28. Use the up and down arrows at the top of the dialog box to put your three rules in the proper order: red, yellow, green.
  29. Click 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, which is why you need to do step 28. 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.

Related Tips:

Document and Annotate! One of the easily overlooked tools provided by Word is the ability to add footnotes and endnotes to your documents. WordTips: Footnotes and Endnotes is the definitive resource guide to using these tools to enhance your documents. Check out WordTips: Footnotes and Endnotes today!