Highlight records based on overlapping date ranges and a condition
Hi, I have a situation where I want to count if this value is duplicate and if it the dates are overlapping as well. Is there anyway to work this out?
eg
Serial | Start date | End Date
ABC | 01.01.2009 | 31.12.2009
BCD | 01.06.2009 | 31.12.2009
ABC | 01.07.2009 | 30.06.2010
So it should list the first and third entry.
Answer:
The image above demonstrates a conditional formatting formula that highlights records based on a condition (column B) and date ranges (column C and D).
Records on row 3 and 5 are highlighted, they share the same condition in column B and their date ranges overlap.
How to apply conditional formatting formula to the data set
- Select a cell range
- Press with left mouse button on the "Home" tab
- Press with left mouse button on "Conditional Formatting" button
- Press with left mouse button on "New Rule.."
- Press with left mouse button on "Use a formula to determine which cells to format"
- Type =SUMPRODUCT(($C3<=$D$3:$D$6)*($D3>=$C$3:$C$6)*($B3=$B$3:$B$6))>1 in "Format values where this formula is TRUE" window.
- Press with left mouse button on "Format.." button
- Press with left mouse button on "Fill" tab
- Select a color for highlighting cells.
- Press with left mouse button on "Ok"
- Press with left mouse button on "Ok"
- Press with left mouse button on "Ok"
Explaining CF formula in cell B3
The formula is a conditional formatting formula, however, you can enter it in cell E3. Then copy the cell and paste to cells below.
Select cell E3 and then start the "Evaluate Formula" tool on the "Formula" tab on the ribbon.
Press with left mouse button on "Evaluate" button to go through each calculation step.
Step 1 - Check if cells are equal to cell value
The equal sign lets you compare a cell value with a range. If it is the same the logical expression returns TRUE, if not FALSE.
$B3 is locked to column B, however, the row number changes as the CF formula is applied to cells below.
$B3=$B$3:$B$6
becomes
"ABC "={"ABC ";"BCD ";"ABC ";"ABC "}
and returns {TRUE;FALSE;TRUE;TRUE}.
Step 2 - Check if date ranges overlap
The following two logical expressions check which date ranges overlap with the first record. The parenthes make sure that the order of calculation is correct. We want the comparisons to be performed first and then multiply the arrays.
($C3<=$D$3:$D$6)*($D3>=$C$3:$C$6)
becomes
(39814<={40178;40178;40359;39813})* (40178>={39814;39965;39995;39600})
{TRUE;TRUE;TRUE;FALSE}* {TRUE;TRUE;TRUE;TRUE}
and returns {1;1;1;0}
Step 3 - Multiply arrays
($C3<=$D$3:$D$6)*($D3>=$C$3:$C$6)*($B3=$B$3:$B$6)
{TRUE;FALSE;TRUE;TRUE}* {1;1;1;0}
and returns {1;0;1;0}
Step 4 - Sum values in array
SUMPRODUCT(($C3<=$D$3:$D$6)*($D3>=$C$3:$C$6)*($B3=$B$3:$B$6))
becomes
SUMPRODUCT({1;0;1;0})
and returns 2.
Step 5 - Check if sum is larger than 1
SUMPRODUCT(($C3<=$D$3:$D$6)*($D3>=$C$3:$C$6)*($B3=$B$3:$B$6))>1
becomes
2>1
and returns TRUE. Cell B3 is highlighted.
Get Excel *.xlsx file
duplicate values and overlapping dates.xlsx
Recommended reading
Built-in conditional formatting
Data Bars Color scales IconsHighlight cells rule
Highlight cells containing stringHighlight a date occuring
Highlight cells equal to
Highlight unique/duplicates
Top bottom rules
Highlight top 10 valuesHighlight top 10 % values
Highlight above average values
Basic CF formulas
Working with Conditional Formatting formulasFind numbers in close proximity to a given number
Highlight empty cells
Highlight text values
Search using CF
Highlight records – multiple criteria [OR logic]Highlight records [AND logic]
Highlight records containing text strings (AND Logic)
Highlight lookup values
Unique distinct
How to highlight unique distinct valuesHighlight unique values and unique distinct values in a cell range
Highlight unique values in a filtered Excel table
Highlight unique distinct records
Duplicates
How to highlight duplicate valuesHighlight duplicates in two columns
Highlight duplicate values in a cell range
Highlight smallest duplicate number
Highlight more than once taken course in any given day
Highlight duplicates with same date, week or month
Highlight duplicate records
Highlight duplicate columns
Highlight duplicates in a filtered Excel Table
Compare
Highlight missing values between to columnsCompare two columns and highlight values in common
Compare two lists of data: Highlight common records
Compare tables: Highlight records not in both tables
How to highlight differences in price lists
Compare two columns and highlight differences
Min max
Highlight smallest duplicate numberHow to highlight MAX and MIN value based on month
Highlight closest number
Dates
Highlight dates in a date rangeHow to highlight MAX and MIN value based on month
Highlight odd/even months
Highlight overlapping date ranges using conditional formatting
Highlight records based on overlapping date ranges and a condition
Highlight date ranges overlapping selected record [VBA]
How to highlight weekends [Conditional Formatting]
How to highlight dates based on day of week
Highlight current date
Misc
Highlight every other rowDynamic formatting
How to change cell formatting using a Drop Down list
Highlight cells based on ranges
Highlight opposite numbers
Highlight cells based on coordinates
Excel categories
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.