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

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,783
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
IdentifierSMSYEMEY
M10306960000001031994121997
M10306960000001031994121997
M10306960000001031994121997
M18912550000000062016122016
M18912550000000062016122016
M18912550000000062016122016
M18900900000002022015
M18900900000002022015
M18900900000002022015
M18912170000007052016
M18912170000007052016
M18912170000007052016

<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>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: center"]5[/TD]
[TD="bgcolor: #FFFF00"]M10306960000002[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"]03[/TD]
[TD="bgcolor: #FFFF00"]1994[/TD]
[TD="bgcolor: #FFFF00"]12[/TD]
[TD="bgcolor: #FFFF00"]1995[/TD]

[TD="align: center"]6[/TD]
[TD="bgcolor: #FFFF00"]M10306960000002[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"]03[/TD]
[TD="bgcolor: #FFFF00"]1994[/TD]
[TD="bgcolor: #FFFF00"]12[/TD]
[TD="bgcolor: #FFFF00"]1999[/TD]

[TD="align: center"]7[/TD]
[TD="bgcolor: #FFFF00"]M10306960000002[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"]03[/TD]
[TD="bgcolor: #FFFF00"]1994[/TD]
[TD="bgcolor: #FFFF00"]12[/TD]
[TD="bgcolor: #FFFF00"]1999[/TD]

[TD="align: center"]8[/TD]

[TD="align: center"]9[/TD]

[TD="align: center"]10[/TD]

[TD="align: center"]11[/TD]
[TD="bgcolor: #FFFF00"]M18900900000001[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"]02[/TD]
[TD="bgcolor: #FFFF00"]2015[/TD]
[TD="bgcolor: #FFFF00"]12[/TD]
[TD="bgcolor: #FFFF00"]2015[/TD]

[TD="align: center"]12[/TD]
[TD="bgcolor: #FFFF00"]M18900900000001[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"]02[/TD]
[TD="bgcolor: #FFFF00"]2015[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]

[TD="align: center"]13[/TD]
[TD="bgcolor: #FFFF00"]M18900900000001[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"]02[/TD]
[TD="bgcolor: #FFFF00"]2015[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]

[TD="align: center"]14[/TD]

[TD="align: center"]15[/TD]

[TD="align: center"]16[/TD]

[TD="align: center"]17[/TD]
[TD="bgcolor: #FFFF00"]M18912170000009[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"]04[/TD]
[TD="bgcolor: #FFFF00"]2015[/TD]
[TD="bgcolor: #FFFF00"]04[/TD]
[TD="bgcolor: #FFFF00"]2017[/TD]

[TD="align: center"]18[/TD]
[TD="bgcolor: #FFFF00"]M18912170000009[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"]04[/TD]
[TD="bgcolor: #FFFF00"]2016[/TD]
[TD="bgcolor: #FFFF00"]04[/TD]
[TD="bgcolor: #FFFF00"]2017[/TD]

[TD="align: center"]19[/TD]
[TD="bgcolor: #00B0F0"]M18912170000002[/TD]
[TD="bgcolor: #00B0F0"][/TD]
[TD="bgcolor: #00B0F0"][/TD]
[TD="bgcolor: #00B0F0"]02[/TD]
[TD="bgcolor: #00B0F0"]2015[/TD]
[TD="bgcolor: #00B0F0"]12[/TD]
[TD="bgcolor: #00B0F0"]2015[/TD]

[TD="align: center"]20[/TD]
[TD="bgcolor: #00B0F0"]M18912170000002[/TD]
[TD="bgcolor: #00B0F0"][/TD]
[TD="bgcolor: #00B0F0"][/TD]
[TD="bgcolor: #00B0F0"]01[/TD]
[TD="bgcolor: #00B0F0"]2016[/TD]
[TD="bgcolor: #00B0F0"]12[/TD]
[TD="bgcolor: #00B0F0"]2016[/TD]

[TD="align: center"]21[/TD]
[TD="bgcolor: #00B0F0"]M18912170000002[/TD]
[TD="bgcolor: #00B0F0"][/TD]
[TD="bgcolor: #00B0F0"][/TD]
[TD="bgcolor: #00B0F0"]01[/TD]
[TD="bgcolor: #00B0F0"]2017[/TD]
[TD="bgcolor: #00B0F0"][/TD]
[TD="bgcolor: #00B0F0"][/TD]

[TD="align: center"]22[/TD]

[TD="align: center"]23[/TD]

[TD="align: center"]24[/TD]

</tbody>

Edit

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

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
[TABLE="class: cms_table"]
<tbody>[TR]
[TD]M10306960000001[/TD]
[TD][/TD]
[TD][/TD]
[TD]03[/TD]
[TD]1994[/TD]
[TD]12[/TD]
[TD]1997[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="bgcolor: #FFFF00"]M10306960000002[/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"][/TD]
[TD="bgcolor: #FFFF00"]03[/TD]
[TD="bgcolor: #FFFF00"]1994[/TD]
[TD="bgcolor: #FFFF00"]12[/TD]
[TD="bgcolor: #FFFF00"]1995

is the 001 the same as 002[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
No its a different number, they need to match in C (K)
 
Upvote 0
sorry - but I still do not know what you want - try asking again with a pretend scenario eg fruit prices or whatever
 
Upvote 0
1. Data needs to match in column C.
2. It then needs to look at start and end dates.
3. If the rows match in C the date range in N & O should always be equal or later to the date range of P & Q of the previous row.
 
Upvote 0
row 5 first time number has appeared so why is it yellow - if it is the same in row C why not show us rows C to Q
 
Upvote 0
I don't think it is necessary for you to see what is between C & Q plus its sensitive data. And I don't understand your post 12, I don't know where the 5 came from.
 
Upvote 0
sensitive data - overwrite it with random numbers

[TABLE="width: 327"]
<colgroup><col><col><col span="3"></colgroup><tbody>[TR]
[TD]id[/TD]
[TD]date[/TD]
[TD]amount[/TD]
[TD]lower[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]01/04/2018[/TD]
[TD="align: right"]27[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]02/04/2018[/TD]
[TD="align: right"]31[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]03/04/2018[/TD]
[TD="align: right"]35[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: right"]04/04/2018[/TD]
[TD="align: right"]39[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]05/04/2018[/TD]
[TD="align: right"]43[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]01/04/2018[/TD]
[TD="align: right"]47[/TD]
[TD]L[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]07/04/2018[/TD]
[TD="align: right"]51[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: right"]08/04/2018[/TD]
[TD="align: right"]55[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]09/04/2018[/TD]
[TD="align: right"]59[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]10/04/2018[/TD]
[TD="align: right"]63[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]11/04/2018[/TD]
[TD="align: right"]67[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: right"]12/04/2018[/TD]
[TD="align: right"]71[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]08/04/2018[/TD]
[TD="align: right"]75[/TD]
[TD]L[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]14/04/2018[/TD]
[TD="align: right"]79[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]15/04/2018[/TD]
[TD="align: right"]83[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: right"]16/04/2018[/TD]
[TD="align: right"]87[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="colspan: 2"]is this correct[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
In your original post, row 3 (03/1994) is less than row 2 (12/1997) yet it's not flagged as incorrect. What makes this row correct? Also, if an error is found, do you want to highlight all rows containing that identifier?

WBD
 
Upvote 0
Quick first draft of code give this:


Book1
CDEFGHIJKLMNOPQ
1IdentifierIdentifierSMSYEMEY
2M10306960000001M1030696000000131994121997
3M10306960000001M1030696000000131994121997
4M10306960000001M1030696000000131994121997
5M10306960000002M1030696000000231994121995
6M10306960000002M1030696000000231994121999
7M10306960000002M1030696000000231994121999
8M18912550000000M1891255000000062016122016
9M18912550000000M1891255000000062016122016
10M18912550000000M1891255000000062016122016
11M18900900000001M1890090000000122015122015
12M18900900000001M1890090000000122015
13M18900900000001M1890090000000122015
14M18900900000002M1890090000000222015
15M18900900000002M1890090000000222015
16M18900900000002M1890090000000222015
17M18912170000009M189121700000094201542017
18M18912170000009M189121700000094201642017
19M18912170000002M1891217000000222015122015
20M18912170000002M1891217000000212016122016
21M18912170000002M1891217000000212017
22M18912170000007M1891217000000752016
23M18912170000007M1891217000000752016
24M18912170000007M1891217000000752016
Sheet1


WBD
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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