Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Conditional Formatting Based on Date Proximity.

Conditional Formatting Based on Date Proximity

by Allen Wyatt
(last updated March 19, 2016)

7

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. (See Figure 1.)
  4. Figure 1. The Conditional Formatting Rules Manager dialog box.

  5. 4.` Click New Rule. Excel displays the New Formatting Rule dialog box.
  6. In the Select a Rule Type area at the top of the dialog box, choose Format Only Cells that Contain. (See Figure 2.)
  7. Figure 2. The New Formatting Rule dialog box.

  8. In the Edit the Rule Description area, change the second drop-down list to Equal To.
  9. 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.
  10. Click Format to display the Format Cells dialog box and display the Fill tab.
  11. Specify that you want the color of the cell to be red.
  12. 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.
  13. Click OK. The New Formatting Rule dialog box disappears and the newly defined rule is shown in the Conditional Formatting Rules Manager dialog box.
  14. 12.` Click New Rule. Excel again displays the New Formatting Rule dialog box.
  15. In the Select a Rule Type area at the top of the dialog box, choose Format Only Cells that Contain.
  16. In the Edit the Rule Description area, change the second drop-down list to Is Between.
  17. 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.
  18. Click Format to display the Format Cells dialog box and display the Fill tab.
  19. Specify that you want the color of the cell to be yellow.
  20. 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.
  21. Click OK. The New Formatting Rule dialog box disappears and the newly defined rule is shown in the Conditional Formatting Rules Manager dialog box.
  22. 20.` Click New Rule. Excel again displays the New Formatting Rule dialog box.
  23. In the Select a Rule Type area at the top of the dialog box, choose Format Only Cells that Contain.
  24. In the Edit the Rule Description area, change the second drop-down list to Is Between.
  25. 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.
  26. Click Format to display the Format Cells dialog box and display the Fill tab.
  27. Specify that you want the color of the cell to be green.
  28. 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.
  29. Click OK. The New Formatting Rule dialog box disappears and the newly defined rule is shown in the Conditional Formatting Rules Manager dialog box.
  30. 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.
  31. 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 criterion 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 (6287) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel 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

Absolutely Getting Rid of Formatting

Need to get rid of the formatting applied to a bunch of text? One of the easiest ways to do this is to use Notepad in ...

Discover More

Offering Options in a Macro

When creating macros, you often need to offer a series of choices to a user. This tip demonstrates how easy it is to offer ...

Discover More

Repaginating in a Macro

When creating a macro that extensively processes a document, you may need to periodically force Word to repaginate the ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Working with Multiple Conditions

When you apply conditional formatting, you are not limited to using a single condition. Indeed, you can set up multiple ...

Discover More

Shading Based on Odds and Evens

You can use conditional formatting to add shading to various cells in your worksheet. This tip shows how you can shade cells ...

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
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}] 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 3 + 8?

2017-05-10 03:02:20

Steve J

Colin.
The formula you need is
=AND(A5="",A4<=TODAY()-30)
Adjust cell references as required.
It checks that A5 is blank AND A4 is older or equal to today.
HTH

Steve


2017-05-09 22:09:31

Colin

I want to change a cell red when the date has passed 30 days on the condition that another cell date has not been entered yet. I have looked online a lot and can't find out how to do it.


2017-01-07 06:37:26

Steve Jez

@Bill
Your Conditional formatting rules will need to be 3 between & ignore steps 6 & 7 above. the rules should be like
cellvalue between =$D$16-30 =$D$16+30
etc etc.
The $ signs in the D16 address are essential otherwise as the formatting goes down your column of dates D16 becomes D17, D18 etc.
Also try making the first rule 30 then 60 then 90.


2017-01-05 19:58:09

Bill Nees

Mr. Wyatt
In cell D16 I have a date, 03/17/17.

This date is an expiration date.

I have tried to condition format this cell to change to green when todays date is within 90 days, and yellow within 60 days, then red within 30 days.

No matter how I arrange them, the cell stays whatever color when it gets to the first format.

Is there a way to write this formula so that it only is green from 90 to 60 days, then turns yellow from 60 to 30 days, then turns red from 30 days?

D16 never changes till I set a new expiration date.

I am a truck driver, and don’t understand much about formulas in spread sheets, although I am trying.

Thank you for your help if you can.
Thanks anyway if you can’t.

Bill


2016-06-07 18:17:10

The Original Buzz

Thank you for making my life so much easier. I use Excel more than any other program and will definitely be a regular visitor to this site.


2016-03-22 00:09:02

Sunae Hwang

Hi,
I followed the exactly but it only shows green whether enter the cell value for today's date, +-week, or +-two weeks. Why it's not working for me? I went through twice to make sure I didn't leave anything out. I am using Office 2010.
Thank you.


2016-03-20 07:22:33

Chris Finn

I do this a lot at work in my big spread-sheet to remind me when the instruments in my care are due for calibration.

I don't set a condition for the green boxes. I just set them manually to green fill, then when the date nears, this changes to yellow, and of course(if I have overlooked one!) to RED.

And I have lots of macros on buttons to sort the instrument list by name, by asset number, by date due, etc.

Excel helps me a lot - I can't imagine life without it.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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.