# 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?

#### sharky12345

##### Well-known Member
You're welcome & thanks for the feedback.
As is usually the case Fluff I have 1 further question!

I've got the result of zero for an occasion where the last time/date before the relevant one was the day before, (i.e. before midnight). Can this be accounted for in your formula? I can work round it if not.

### Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

#### Fluff

##### MrExcel MVP, Moderator
That should not matter, it will still pick up the value from col E

Replies
1
Views
203
Replies
5
Views
122
Replies
33
Views
785
Replies
2
Views
85
Replies
6
Views
236

1,130,321
Messages
5,641,518
Members
417,213
Latest member
wikk

### 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.

### Which adblocker are you using?

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