Find the last date/time with criteria

sharky12345

Well-known Member
I'm trying to find a way I can identify the last date and time in a range but with the condition that it does not fall after another date/time.

So range A2:A1000 has a serial number, range B2:B1000 has a date and time stamp - there will be duplicates of the serial number but each time stamp is unique. On another sheet I have the serial numbers in range C2:C1000 and further date/time stamps in range D2:D1000, I have other data in the range E2:1000.

What I need to do is lookup the value in column A of the first sheet, find it in column C of the 2nd sheet, then go through column D of the 2nd sheet, (where the value in A matches), and find the last date/time without going past the original time in column B of the first sheet, then give me the value from column E on the 2nd.

I've tried to explain as best I can, I know it sound really complicate but maybe this will assist;

So this is sheet 1:

Test workbook.xlsm
AB
1Serial NumberSign Date
2CR200002063401/10/2020 01:22
3CR200002063401/10/2020 01:50
4CR200002063501/10/2020 01:23
5CR200002063501/10/2020 01:51
6CR200002063501/10/2020 02:20
7CR200002063501/10/2020 02:49
8CR200002063501/10/2020 03:13
9CR200002063501/10/2020 03:44
10CR200002063501/10/2020 04:10
Sheet1

And this is sheet 2:

Test workbook.xlsm
CDE
1SerialTimestampValue to return
2CR200002063401/10/2020 01:2015
3CR200002063401/10/2020 01:4930
4CR200002063501/10/2020 01:2160
5CR200002063501/10/2020 01:4515
6CR200002063501/10/2020 02:1030
7CR200002063501/10/2020 02:3915
8CR200002063501/10/2020 03:0360
9CR200002063501/10/2020 03:4360
10CR200002063501/10/2020 04:0930
Sheet2

So if I looked up the time stamp in B2 on sheet 1, the value I'd expect to return is 15, which is the value from E2 on sheet 2. If I looked up the time stamp in B6 on sheet 1 I'd expect the return value to be 30, from E6 on the 2nd sheet.

Does my explanation make sense or have I confused the hell out of everyone?

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

sandy666

Banned - Rules violations
is that what you want?
 Serial Number Sign Date Serial Timestamp Value to return Serial Number Last V2R CR2000020634 01/10/2020 01:22:59 CR2000020634 01/10/2020 01:20:59 15 CR2000020634 01/10/2020 01:50 30 CR2000020634 01/10/2020 01:50:03 CR2000020634 01/10/2020 01:49:03 30 CR2000020635 01/10/2020 04:10 60 CR2000020635 01/10/2020 01:23:39 CR2000020635 01/10/2020 01:21:39 60 CR2000020635 01/10/2020 01:51:15 CR2000020635 01/10/2020 01:45:15 15 CR2000020635 01/10/2020 02:20:28 CR2000020635 01/10/2020 02:10:28 30 CR2000020635 01/10/2020 02:49:39 CR2000020635 01/10/2020 02:39:39 15 CR2000020635 01/10/2020 03:13:31 CR2000020635 01/10/2020 03:03:31 60 CR2000020635 01/10/2020 03:44:19 CR2000020635 01/10/2020 03:43:19 60 CR2000020635 01/10/2020 04:10:14 CR2000020635 01/10/2020 04:09:14 30

Fluff

MrExcel MVP, Moderator
Excel Formula:
``=INDEX(Sheet2!\$E\$2:\$E\$10,AGGREGATE(14,6,(ROW(Sheet2!\$D\$2:\$D\$10)-ROW(Sheet2!\$D\$2)+1)/(Sheet2!\$C\$2:\$C\$10=A2)/(Sheet2!\$D\$2:\$D\$10<B2),1))``

sharky12345

Well-known Member
I'll try both suggestions and come back to you!!

sharky12345

Well-known Member

is that what you want?
 Serial Number Sign Date Serial Timestamp Value to return Serial Number Last V2R CR2000020634 01/10/2020 01:22:59 CR2000020634 01/10/2020 01:20:59 15 CR2000020634 01/10/2020 01:50 30 CR2000020634 01/10/2020 01:50:03 CR2000020634 01/10/2020 01:49:03 30 CR2000020635 01/10/2020 04:10 60 CR2000020635 01/10/2020 01:23:39 CR2000020635 01/10/2020 01:21:39 60 CR2000020635 01/10/2020 01:51:15 CR2000020635 01/10/2020 01:45:15 15 CR2000020635 01/10/2020 02:20:28 CR2000020635 01/10/2020 02:10:28 30 CR2000020635 01/10/2020 02:49:39 CR2000020635 01/10/2020 02:39:39 15 CR2000020635 01/10/2020 03:13:31 CR2000020635 01/10/2020 03:03:31 60 CR2000020635 01/10/2020 03:44:19 CR2000020635 01/10/2020 03:43:19 60 CR2000020635 01/10/2020 04:10:14 CR2000020635 01/10/2020 04:09:14 30
Sandy666 sorry that doesn't give me what I'd expect...

sharky12345

Well-known Member
Excel Formula:
``=INDEX(Sheet2!\$E\$2:\$E\$10,AGGREGATE(14,6,(ROW(Sheet2!\$D\$2:\$D\$10)-ROW(Sheet2!\$D\$2)+1)/(Sheet2!\$C\$2:\$C\$10=A2)/(Sheet2!\$D\$2:\$D\$10<B2),1))``
Fluff thanks - is there anything you can think of that would produce a #NUM error?

sandy666

Banned - Rules violations

Sandy666 sorry that doesn't give me what I'd expect...
so show expected result

Fluff

MrExcel MVP, Moderator
is there anything you can think of that would produce a #NUM error?
There is no date/time in sheet2 less than the date/time in sheet1 for that serial number.

sharky12345

Well-known Member
so show expected result
Well in your example, serial number 634 with a sign date of 01/10/2020 01:22:59 should produce 15 because 01:20:59 is the last time.

Fluff

MrExcel MVP, Moderator
It does
+Fluff v2.xlsm
ABCDE
1SerialTimestampValue to return
2CR200002063401/10/2020 01:2015
3CR200002063401/10/2020 01:4930
4CR200002063501/10/2020 01:2160
5CR200002063501/10/2020 01:4515
6CR200002063501/10/2020 02:1030
7CR200002063501/10/2020 02:3915
8CR200002063501/10/2020 03:0360
9CR200002063501/10/2020 03:4360
10CR200002063501/10/2020 04:0930
11
Sheet2

+Fluff v2.xlsm
ABC
1Serial NumberSign Date
2CR200002063401/10/2020 01:2215
3CR200002063401/10/2020 01:5030
4CR200002063501/10/2020 01:2360
5CR200002063501/10/2020 01:5115
6CR200002063501/10/2020 02:2030
7CR200002063501/10/2020 02:4915
8CR200002063501/10/2020 03:1360
9CR200002063501/10/2020 03:4460
10CR200002063501/10/2020 04:1030
Sheet1
Cell Formulas
RangeFormula
C2:C10C2=INDEX(Sheet2!\$E\$2:\$E\$10,AGGREGATE(14,6,(ROW(Sheet2!\$D\$2:\$D\$10)-ROW(Sheet2!\$D\$2)+1)/(Sheet2!\$C\$2:\$C\$10=A2)/(Sheet2!\$D\$2:\$D\$10<B2),1))

Replies
1
Views
194
Replies
5
Views
113
Replies
33
Views
777
Replies
2
Views
79
Replies
6
Views
223

1,129,943
Messages
5,639,116
Members
417,073
Latest member
CBG_Christian

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.

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

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