Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Written by Allen Wyatt (last updated October 5, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


22

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, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Capturing a Screen

A picture is worth a thousand words, but getting the picture—particularly a screen shot—into a workbook may ...

Discover More

Problem with Menus Crashing Word

What do you do if, one day, one of your Word menus suddenly stops working and actually crashes the program? Here's the ...

Discover More

Using the MROUND Worksheet Function

If you want to round a value to some multiple of a whole number, you'll want to become familiar with the MROUND function. ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Conditionally Formatting for Multiple Date Comparisons

When you compare dates in a conditional formatting rule, you need to be careful how you put your comparisons together. Do ...

Discover More

Defining a Single Conditional Formatting Condition

Conditional formatting is a powerful tool you can use to dynamically adjust the formatting of your worksheet. This tip ...

Discover More

Conditional Format that Checks for Data Type

Conditional formatting can be used to highlight cells that contain the improper type of data for your needs. This tip ...

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}] (all 7 characters, in the sequence shown) 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 8 - 5?

2020-10-26 16:54:16

Ali

Thank you, super helpful! The summary worked well. There was one part that was unclear (not sure if it is because I have a Mac version of the Office Suite), I had to click on "Classic" in order to find the formatting type.

Is there a way to automate a report from this? Say that the I want a report to run daily to summarize and rows that have a red cell? I assume there is a way, so a better question is whether someone without experience writing scripts can pull this off?


2020-10-26 12:10:51

Ali

Thank you, super helpful! The summary worked well. There was one part that was unclear (not sure if it is because I have a Mac version of the Office Suite), I had to click on "Classic" in order to find the formatting type.

Is there a way to automate a report from this? Say that the I want a report to run daily to summarize and rows that have a red cell? I assume there is a way, so a better question is whether someone without experience writing scripts can pull this off?


2020-10-26 10:51:25

Ali

Thank you, super helpful! The summary worked well. There was one part that was unclear (not sure if it is because I have a Mac version of the Office Suite), I had to click on "Classic" in order to find the formatting type.

Is there a way to automate a report from this? Say that the I want a report to run daily to summarize and rows that have a red cell? I assume there is a way, so a better question is whether someone without experience writing scripts can pull this off?


2020-10-22 12:32:49

Toba

Thanks for the tips. Very valuable for me. Just use for a quick working excel file.


2020-01-04 15:54:08

J. Woolley

@Robert Nye (part 2)
Assuming the cells containing your dates are $D$1:$D$25, the final conditional formatting rules should look like this:
(see Figure 1 below)

Figure 1. 


2020-01-04 15:49:13

J. Woolley

@Robert Nye
Select the cells containing your dates, then apply these 3 rules using procedures described in the Tip:

(see Figure 1 below)

(see Figure 2 below)

(see Figure 3 below)

Figure 1. 

Figure 2. 

Figure 3. 


2020-01-03 14:49:42

Robert Nye

I am trying to get a cell to change colors depending on the date. I will put a certification date in a cell, i need that cell to be green from the date entered to 21 months past the date entered than i need the date to be yellow from 21 months past to 24 months past and red for anything past 24 months. could i get help with this formula please.
Thank you.


2019-05-01 07:53:58

Alan Bahnam

Ok, I am stumped, I have used this formula and I cannot get it to work properly. I have a column (m33 Order Survey) which will get a date when the survey gets ordered, then I have a column (o33 Rcv Survey). I need the m33 column to turn green when the initial date is entered and turn red after 12 days if the (o33 Rcv Survey) never gets a date or date entered exceeds 12 days. Please help. Thanks


2019-01-03 08:53:52

Peter Atherton

Natalie

I forget to say that You base the condiional format on the helper column


2019-01-03 08:48:31

Peter Atherton

Natalie

Assuming that the dates are in column B and the entry date is in column C, try this

Private Sub Worksheet_Change(ByVal Target As Range)
Dim dt As Date
dt = Now
dt = Format(dt, "dd/mm/yyyy")
If Target.Column <> 2 Then Exit Sub
Target.Offset(0, 1).Value = dt
End Sub

Right-click the worksheet Tab and select the View Code and paste the code into the module.

HTH


2019-01-01 17:37:34

Natalie

I need to know how to format cells (change cell color) based on DATE OF ENTRY.
Like, say the date I have entered is 1/15/19 but the date I ENTERED the text is 1/3/19... that is what I need to format.
I need to format the cells so that they change color after 30 days have passed since ORIGINAL ENTRY DATE, as opposed to the actual date entered.
Does that make sense? Is there even a way to do it?
It's driving me crazy. I appreciate the help!


2018-04-13 07:03:53

Steve Jez

Bobby O,
Depending on how stringent your requirements for conditional formatting are, the following will work. Assuming the cell containing your start date is named as startdate.

=AND(ISNUMBER(D4),D4<>startdate)

As excel stores dates as a number (regardless of what is displayed on screen) any number will trigger the conditional formatting. If you want to limit the permitted dates you can add another AND condition such as "<=startdate+365" (without the quotes) would only trigger formatting if the date is within a year of the startdate.

HTH

Steve


2018-04-12 16:12:43

Bobby O

it was possible, using conditional formatting, to change the color of a cell when you type any date in the cell.
for instance, I have Cells A2:G34 highlighted in Light Gray. When I type a date (any date) other than the Start Date,
I want the color to turn Green.
What formula would you suggest?
Thank you,
BobbyO


2018-03-02 05:21:13

Steve Jez

Jake,
Three rules,
Select F2:F35
Conditional Formatting
Use formula to determine which cells to format
New Rule

=F5>TODAY()+60 (Format fill Green)
=AND(F5>=TODAY()+31,F5<=TODAY()+60) (Format fill Yellow)
=F5<=TODAY()+30 (Format fill Red)

Hope this helps

Steve


2018-03-01 10:03:59

Jake

I am military and we have certs that last a year and some items that have expiration dates.

I have these in separate columns so that I can format them to turn red when the expiration date is within 30 days, turns yellow 31-60 days from expiration and, green for anything greater than 61+ days. I have followed the formulas and even skipped steps 5 and 6 as suggested for bill. they are in Colum F and go from row 2 to row 35.

I can not get them to turn any colors at all. what would my manage rules tab look like.


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.