Highlight duplicates based on date range in another column

neilskinner

New Member
Joined
Apr 25, 2022
Messages
9
Office Version
  1. 2010
Platform
  1. Windows
Hello,

Can anyone help me with a conditional formatting formula to highlight duplicate data in column H, but only if data in Column I (dates) are at least 2 weeks apart? We are keeping track on railcar numbers and their dates of arrival. If there is a duplicate entry of a railcar but the arrival dates are greater than two weeks apart, we know that this is accurate. However, if arrival dates are within two weeks we know that this data is duplicated and should be highlighted. Any help would be greatly appreciated!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Welcome to the MrExcel forum!

Try:

Book1
AB
1CarDate
21231-Jan
34562-Jan
47893-Jan
51231-Feb
64562-Feb
712310-Feb
82221-Mar
94561-Mar
103334-Mar
114568-Mar
12
13
14
15
16
17
18
19
20
Sheet10
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:A19Expression=(A2<>"")*((B2-MAX(IF((A$2:A$20=A2)*(B$2:B$20<B2),B$2:B$20))<14)+(MIN(IF((A$2:A$20=A2)*(B$2:B$20>B2),B$2:B$20,99999))-B2<14))textNO
 
Upvote 0
=(h2<>"")*((k2-MAX(IF((h$2:h$20000=h2)*(k$2:k$20000<k2),k$2:k$20000))<14)+(MIN(IF((h$2:h$20000=h2)*(k$2:k$20000>k2),k$2:k$20000,99999))-k2<14))

Eric, thanks for your help yesterday. I basically just changed your cells to my cells. Your "A" cell is my "H" cell. Your "B" cell is my "K" cell. Do you see anything off in the above formula? Do I need to have the date column in a certain format for the formula to run correctly? I am getting some highlights, but they aren't highlight duplicates. I'm guessing that I transposed something wrong when I typed in the formula into the box.
 
Upvote 0
Your adjustments to the formula are correct.

Book1
HIJK
1CarDate
21231-Jan
34562-Jan
47893-Jan
51231-Feb
64562-Feb
712310-Feb
82221-Mar
94561-Mar
103334-Mar
114568-Mar
12
Sheet10
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H2:H2000Expression=(H2<>"")*((K2-MAX(IF((H$2:H$2000=H2)*(K$2:K$2000<K2),K$2:K$20))<14)+(MIN(IF((H$2:H$2000=H2)*(K$2:K$2000>K2),K$2:K$2000,99999))-K2<14))textNO


My biggest suspicion is that there's an issue with the date column. How are the dates stored? Are they an actual Excel date (numeric, but formatted as a date), or a text representation of a date?
 
Upvote 0
I think originally they are formatted as "date". I changed the whole column to "text" and it changed the dates to 5 digit numbers, but to my knowledge, it didn't seem to make a difference
 
Upvote 0
Are you able to provide a sample of your sheet, with your data? If you could use the XL2BB tool (see the link in my signature or the reply box), it would greatly facilitate the process. It's easy to download, install and use. My samples above used it.
 
Upvote 0
Fastweigh Rail Cars.xlsx
HIJK
1RAIL CARWEIGHTSTONSARRIVED
2ACFX 22012514785973.92951/11/2022
3ACFX 22013615088775.4435
4ADMX 101318595092.9754/4/2022
5ADMX 11218768093.84
6ADMX 2100519176095.883/30/2022
7ADMX 2101019174095.873/27/2022
8ADMX 2540218660093.34/21/2022
9ADMX 2543218636093.184/25/2022
10ADMX 2547518632093.164/13/2022
11ADMX 2561518672093.363/25/2022
12ADMX 2582818714093.574/4/2022
13ADMX 2619818672093.364/17/2022
14ADMX 2641318648093.243/30/2022
15ADMX 3026719628098.14
16ADMX 3027319674098.374/21/2022
17ADMX 30731221160110.58
18ADMX 30733220200110.14/13/2022
19ADMX 30734221240110.624/6/2022
20ADMX 30796221180110.594/21/2022
21ADMX 30920221160110.584/1/2022
22ADMX 30938220240110.124/8/2022
23ADMX 30949221120110.564/6/2022
24ADMX 30998221120110.564/8/2022
25ADMX 31045221180110.594/17/2022
26ADMX 31062220780110.394/2/2022
27ADMX 31074220260110.134/1/2022
28ADMX 31076220820110.413/25/2022
29ADMX 31114220640110.32
30ADMX 31180221480110.743/20/2022
31ADMX 3119019810099.054/17/2022
32ADMX 31224221400110.74/2/2022
33ADMX 31228220920110.463/19/2022
34ADMX 31256220660110.33
35ADMX 31280221340110.673/27/2022
36ADMX 31280220820110.41
Sheet1
Cell Formulas
RangeFormula
J2:J36J2=I2/2000
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H:HExpression=(H2<>"")*((K2-MAX(IF((H$2:H$20000=H2)*(K$2:K$20000<K2),K$2:K$20000))<14)+(MIN(IF((H$2:H$20000=H2)*(K$2:K$20000>K2),K$2:K$20000,99999))-K2<14))textNO
 
Upvote 0
Thank you for doing that, I was able to spot right off what was off.

Book1
HIJK
1RAIL CARWEIGHTSTONSARRIVED
2ACFX 22012514785973.92951/11/2022
3ACFX 22013615088775.4435
4ADMX 101318595092.9754/4/2022
5ADMX 11218768093.84
6ADMX 2100519176095.883/30/2022
7ADMX 2101019174095.873/27/2022
8ADMX 2101018660093.34/2/2022
9ADMX 2543218636093.184/25/2022
10ADMX 2547518632093.164/13/2022
11ADMX 2561518672093.363/25/2022
12ADMX 2582818714093.574/4/2022
13ADMX 2619818672093.364/17/2022
14ADMX 2641318648093.243/30/2022
15ADMX 3026719628098.14
16ADMX 3027319674098.374/21/2022
17ADMX 30731221160110.58
18ADMX 30733220200110.14/13/2022
19ADMX 30734221240110.624/6/2022
20ADMX 30796221180110.594/21/2022
21ADMX 30920221160110.584/1/2022
22ADMX 30938220240110.124/8/2022
23ADMX 30949221120110.564/6/2022
24ADMX 30998221120110.564/8/2022
25ADMX 31045221180110.594/17/2022
26ADMX 1013220780110.394/2/2022
27ADMX 31074220260110.134/1/2022
28ADMX 31076220820110.413/25/2022
29ADMX 31114220640110.32
30ADMX 31180221480110.743/20/2022
31ADMX 3119019810099.054/17/2022
32ADMX 31224221400110.74/2/2022
33ADMX 31228220920110.463/19/2022
34ADMX 31256220660110.33
35ADMX 31280221340110.673/27/2022
36ADMX 31280220820110.41
Sheet12
Cell Formulas
RangeFormula
J2:J36J2=I2/2000
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H:HExpression=(H1<>"")*(K1<>"")*((K1-MAX(IF((H$1:H$20000=H1)*(K$1:K$20000<K1),K$1:K$20000))<14)+(MIN(IF((H$1:H$20000=H1)*(K$1:K$20000>K1),K$1:K$20000,99999))-K1<14))textNO


The main difference was that when I selected the range to apply the Conditional Formatting to, I selected H2:H20. You selected the entire H column. When you create a Conditional Formatting formula, you need to make the cell reference in it refer to the upper left corner of the selected range. In my case, that was H2, in yours, H1. That's the biggest reason it didn't work right. I also added another condition at the start that made sure that the K column has a date in it, since you have several rows that don't.

There are 2 reasons I chose H2:H20 as my range. The first is so that H1 wouldn't be highlighted, but it didn't really matter in this case. The second is performance. You'll probably notice that your sheet is a bit sluggish at times. When Excel has to calculate a million rows of data with an array formula, that can take a while. You might get a bit better performance if you keep the formula as is, but just apply it to H1:H20000.

Let me know how it works!
 
Upvote 0
i really appreciate the help. I posted your changes, but I still cant seem to get anything. Sorry to be a bother! Here is another snippet. I feel like it should be highlighting these duplicates but it isnt.

Fastweigh Rail Cars.xlsx
HIJK
326CEFX 360182201150100.5754/25/2022
327CEFX 360182201150100.5754/25/2022
328CEFX 360203200200100.14/25/2022
329CEFX 360203200200100.14/25/2022
330CEFX 360216200500100.254/25/2022
331CEFX 360216200500100.254/25/2022
332CEFX 360256201100100.554/25/2022
333CEFX 360261204100102.05
334CEFX 360283213550106.775
335CEFX 360310209000104.54/21/2022
336CEFX 360321216500108.25
337CEFX 360328212450106.225
338CEFX 360330208300104.15
Sheet1
Cell Formulas
RangeFormula
J326:J338J326=I326/2000
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H:HExpression=(H1<>"")*(K1<>"")*((K1-MAX(IF((H$1:H$20000=H1)*(K$1:K$20000<K1),K$1:K$20000))<14)+(MIN(IF((H$1:H$20000=H1)*(K$1:K$20000>K1),K$1:K$20000,99999))-K1<14))textNO
 
Upvote 0

Forum statistics

Threads
1,215,581
Messages
6,125,657
Members
449,247
Latest member
wingedshoes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top