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 if you are using a version of Excel prior to Excel 2007:
- Select cell A1.
- Choose Conditional Formatting from the Format menu. Excel displays the Conditional Formatting dialog box. (Click here to see a related figure.)
- 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.
- Click on the Format button. Excel displays the Format Cells dialog box.
- Make sure the Patterns tab is selected. (Click here to see a related figure.)
- Choose the red color you want to use and close the Format Cells dialog box.
- Click on the Add button.
- 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.
- Click on the Format button. Excel displays the Format Cells dialog box.
- Make sure the Patterns tab is selected.
- Choose the yellow color you want to use and close the Format Cells dialog box.
- Click on the Add button.
- 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.
- Click on the Format button. Excel displays the Format Cells dialog box.
- Make sure the Patterns tab is selected.
- Choose the green color you want to use and close the Format Cells dialog box.
- Click on OK.
If you are using Excel 2007 then the steps are different. Follow these:
- Select cell A1.
- 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.
- Choose Manage Rules. Excel displays the Conditional Formatting Rules Manager dialog box. (Click here to see a related figure.)
- 4.` Click New Rule. Excel displays the New Formatting Rule dialog box.
- 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.)
- In the Edit the Rule Description area, change the second drop-down list to Equal To.
- 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.
- Click Format to display the Format Cells dialog box and display the Fill tab.
- Specify that you want the color of the cell to be red.
- 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.
- 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.` Click New Rule. Excel again displays the New Formatting Rule dialog box.
- In the Select a Rule Type area at the top of the dialog box, choose Format Only Cells that Contain.
- In the Edit the Rule Description area, change the second drop-down list to Is Between.
- 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.
- Click Format to display the Format Cells dialog box and display the Fill tab.
- Specify that you want the color of the cell to be yellow.
- 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.
- 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.` Click New Rule. Excel again displays the New Formatting Rule dialog box.
- In the Select a Rule Type area at the top of the dialog box, choose Format Only Cells that Contain.
- In the Edit the Rule Description area, change the second drop-down list to Is Between.
- 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.
- Click Format to display the Format Cells dialog box and display the Fill tab.
- Specify that you want the color of the cell to be green.
- 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.
- Click OK. The New Formatting Rule dialog box disappears and the newly defined rule is shown in the Conditional Formatting Rules Manager dialog box.
- 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.
- 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. 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.