Code to highlight rows when data range is before previous date.

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,748
Office Version
  1. 365
Platform
  1. Windows
Tricky one to explain this. I have a file where I need to know if any row of dates are earlier than the rows before. The code first needs to look at column K and all the numbers that match. In the example below I have highlighted in yellow the ones that are incorrect. If you look at N6&7/O6&7 the date is earlier than P5/Q5 above. The same with N12&13/O12&13 is earlier than P11/Q11.

The ones in blue are as it should be, they all follow on from each other. Like I say difficult to explain but please let me know if more clarification is needed.

Excel 2010
KLMNOPQ
1IdentifierSMSYEMEY
2M10306960000001031994121997
3M10306960000001031994121997
4M10306960000001031994121997
5M10306960000002031994121995
6M10306960000002031994121999
7M10306960000002031994121999
8M18912550000000062016122016
9M18912550000000062016122016
10M18912550000000062016122016
11M18900900000001022015122015
12M18900900000001022015
13M18900900000001022015
14M18900900000002022015
15M18900900000002022015
16M18900900000002022015
17M18912170000009042015042017
18M18912170000009042016042017
19M18912170000002022015122015
20M18912170000002012016122016
21M18912170000002012017
22M18912170000007052016
23M18912170000007052016
24M18912170000007052016

<colgroup><col style="width: 25pxpx" https:="" www.mrexcel.com="" forum="" usertag.php?do="list&action=hash&hash=DAE7F5"" target="_blank"></colgroup><colgroup><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>

Edit

In hindsight its probably better if the code looks for matches in column C rather than K please.
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
"If you look at N6&7/O6&7 the date is earlier than P5/Q5 above.2

N6 is 03 P5 is 12 - I do not follow - are N and P both months ?
 
Upvote 0
Yes I am guessing the code would need to put months and years together like 12/2015 and 02/2015. Then it would work out that the rows below are earlier than above. I said it was hard to explain!
 
Upvote 0
If you look at N6&7/O6&7 the date is earlier than P5/Q5 above. The same with N12&13/O12&13 is earlier than P11/Q11.

I just don't underestand - in plain english, why is row 5 colored yellow ?
 
Upvote 0
If you look at N6&7/O6&7 the date is earlier than P5/Q5 above. The same with N12&13/O12&13 is earlier than P11/Q11.

I just don't underestand - in plain english, why is row 5 colored yellow ?

Its just because the 3 rows match in column K, to show those group are wrong. Basically when K matches the dates in the rows below can only be the same date or after, never earlier.
 
Upvote 0
Why not just use conditional formatting, its not exactly as you want the result but give you an area of issues:

Excel 2016 (Windows) 32 bit
K
L
M
N
O
P
Q
1
IdentifierSMSYEMEY
2
M10306960000001
3
1994
12
1997
3
M10306960000001
3
1994
12
1997
4
M10306960000001
3
1994
12
1997
5
M10306960000002
3
1994
12
1995
6
M10306960000002
3
1994
12
1999
7
M10306960000002
3
1994
12
1999
8
M18912550000000
6
2016
12
2016
9
M18912550000000
6
2016
12
2016
10
M18912550000000
6
2016
12
2016
11
M18900900000001
2
2015
12
2015
12
M18900900000001
2
2015
13
M18900900000001
2
2015
14
M18900900000002
2
2015
15
M18900900000002
2
2015
16
M18900900000002
2
2015
17
M18912170000009
4
2015
4
2017
18
M18912170000009
4
2016
4
2017
19
M18912170000002
2
2015
12
2015
20
M18912170000002
1
2016
12
2016
21
M18912170000002
1
2017
22
M18912170000007
5
2016
23
M18912170000007
5
2016
24
M18912170000007
5
2016

<tbody>
</tbody>
Sheet: Sheet1

<tbody>
</tbody>

Excel 2016 (Windows) 32 bit
S
2
=AND(K2=K1,OR(IFERROR(DATE(Q2,P2,1),0)<>IF+$N$1:$Q$24ERROR(DATE(Q1,P1,1),0),IFERROR(DATE(O2,N2,1),0)<>IFERROR(DATE(O1,N1,1),0)),DATE(O2,N2,1)<iferror(date(q1,p1,1),0))< div=""></iferror(date(q1,p1,1),0))<>​

<tbody>
</tbody>
Sheet: Sheet1

<tbody>
</tbody>
 
Last edited:
Upvote 0
Thanks I will try but I preferred a macro as there 100s of thousands of rows
 
Upvote 0
Is the macro just highlighting the subset as you did in your example? What is in Column C that you say should be used instead of column K?
 
Upvote 0
Yes for reasons that will only complicate, the code needs to look at C rather than K
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,185
Members
449,071
Latest member
cdnMech

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