Sorting events and calculating time differences

dbourn

New Member
Joined
May 11, 2010
Messages
9
Hi,
I have been looking and can't seem to get this to work. First, I have two input files that I store into two arrays (Example Below). I need to link a specific event in Array 1 with that in Array 2 and calculate the difference in time. To make it more challenging there may be an event in either array that does not have a corresponding event in the other array. In the example below:

Event A-C occurring at 10:03:12 does not have an accompanying D Event
Event H occurring at 10:04:05 does have an accompanying D event at 10:04:34 (which occurs 29 seconds later).

The criteria to screen this is that the D-event must occur after the event in array 1 and the maximum time later it can occur is MaxDelay.

I want to calculate the time difference and put it in an output array. I am having a heck of a time and can't get the code to obey the above criteria to evaluate which event goes with which D-event. Any tips to point me in the right direction would be greatly appreciated!

Array 1 and 2 are dimmed as date while the output array is dimmed as double. Everything is working up to the point of evaluating the time and associating events.

Array 1
Time Event
10:03:12 PM A-C
10:03:15 PM A-C
10:04:05 PM H
10:04:37 PM H


Array 2
Time Event
10:02:14 PM D
10:04:34 PM D
10:05:10 PM D



Code:
For k = 0 To UBound(Array1, 2)
    Event_Time = Array1(0, k)
    For m = 0 To UBound(Array2, 2)
        If (Event_Time - Array2(0, m)) > 0 And (Event_Time - Array2(0, m)) < (MaxDelay* 0.0001157407) Then
        OutputArray(0, k) = Array1(0, k)
        OutputArray(1, k) = Array2(0, m)
        OutputArray(2, k) = Array1(0, k) - Array2(0, m)
        End If
    Next m
Next k

Many Thanks!
--David
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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