Solved

Compare 2 dates and use conditional formatting if specific column has an older date

Posted on 2013-12-11
9
613 Views
Last Modified: 2013-12-12
Both column P and column R contain dates. I would like to apply conditional formatting to R2 if the date in that cell is older than the date in P2, as that flags a production issue. I only want the conditional formatting applied if both R2 and P2 have dates — if either R2 or P2 is blank, then no conditional formatting is to be applied.

What formula would I use in this situation?

Thanks in advance!
Andrea
0
Comment
Question by:Andreamary
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 50

Expert Comment

by:barry houdini
ID: 39712934
Try using this formula in conditional formatting

=AND(R2<P2,R2<>"")

that can be applied to cell R2 - cell is formatted if it's older than P2 but not blank

regards, barry
0
 
LVL 81

Expert Comment

by:byundt
ID: 39713243
At risk of being a little harder to understand than the AND formula, since dates are always stored as numbers greater than 0, you could use the following Conditional Formatting formula:
=P2/R2>1

If P2 is blank, you get =0/R2>1     which becomes =0>1, which is FALSE--no Conditional Format
If R2 is blank, you get =P2/0>1      which becomes #DIV/0! error value--no Conditional Format
If R2 is later than P2, you get =P2/R2>1     but P2/R2 is less than 1--so FALSE no Conditional Format

If R2 is earlier than P2, you get =P2/R2>1   P2/R2 will be greater than 1--so test is TRUE & Conditional Format will be applied
0
 

Author Comment

by:Andreamary
ID: 39714017
My apologies to you both!!! I overlooked the fact that the dates are prefaced with initials (as per a formula implemented before my time)...sorry about that!

Here are examples of what might be in R2 or P2:

MJ–28 Dec 12
MC–20 Jan 13

Given this, is it still possible to proceed with the date compare as outlined above?

Thanks,
Andrea
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 32

Expert Comment

by:Rob Henson
ID: 39714132
To convert each to a true date you can use:

=DATEVALUE(RIGHT(R2,LEN(R2)-3))

Assumes as per comment that only first 3 characters are note part of the date.

Thanks
Rob H
0
 
LVL 81

Expert Comment

by:byundt
ID: 39714151
If the date portion of the cell value always takes 9 characters (i.e. you use leading zeros on the day), you can use:
=RIGHT(P2,9)/RIGHT(R2,9)>1

Otherwise, you can use:
=MID(P2,FIND("-",P2)+1,20)/MID(R2,FIND("-",R2)+1,20)>1
0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 39714165
byundt - I went with the assumption the other way, that the non-date part was always 3 characters.

I assume you have missed out the DATEVALUE part as Excel would recognise the result as a date when calculating on it so not required. Whereas using the section of my formula without the DATEVALUE would still give a text string until it was referred to in a formula.

Thanks
Rob H
0
 

Author Comment

by:Andreamary
ID: 39714630
Correct me if I'm wrong, but it appears that to obtain the "true date" then, I would have to extract it using the formula above and create a new column for it...? If that's the case, is it possible instead, then, using VBA, to:
interpret the "true date" in column "R" and column "P" as it is currently formatted with initials first without having to extract the date and/or create another column for it
change the cell color in column "R" when the date is older than the date in the corresponding row in Column "P"
leave cell color unchanged if corresponding cells in either column "R" or "P" are blank

Thanks!
Andrea
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39715389
Andrea,
To obtain the "true date" you can either extract the date portion of the cell's text and put it in the DATEVALUE function (as suggested by Rob) or use it in an arithmetic expression (as occurs in the two formulas I suggested in my last Comment). Either way, it is not necessary to create new columns for the dates.

Using Rob's suggestion and barryhoudini's formula, the Conditional Formatting formula would be:
=AND(R2<>"",DATEVALUE(RIGHT(R2,LEN(R2)-3))<DATEVALUE(RIGHT(P2,LEN(P2)-3)))

My formulas (just repeating my previous Comment) for the Conditional Formatting formula are:
=RIGHT(P2,9)/RIGHT(R2,9)>1
=MID(P2,FIND("-",P2)+1,20)/MID(R2,FIND("-",R2)+1,20)>1

The three formulas are making different assumptions about the text in the cell:
Rob assumed there were two initials and a hyphen
My first formula assumed the date would be the last 9 characters in the cell (i.e. three for the month, two for the day and two for the year).
My second formula assumed that the initials would always be followed by a hyphen

You will need to look at how your users fill out the worksheet to determine if any of the three methods will work in all cases--or if the users need to be trained.

Brad
0
 

Author Closing Comment

by:Andreamary
ID: 39715531
Brad,

Thanks so much for an excellent explanation and summary of the 3 possible formulas, which all work! All the assumptions were correct. I will be using the shortest formula.

And thanks as well to Rob and Barry Houdini for your answers, which Brad combined for a successful formula.

Experts Exchange is an impressive resource!

Andrea
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question