I am trying to figure out a way to find the closest number to another number. Here is what my spreadsheet looks like:

Row | time stamp | event # | unit | unit status | |

1 |
<tbody> </tbody> | 1 | e | hold | |

2 |
<tbody> </tbody> | 1 | e | arrive | |

3 | 1420089500 | 1 | e | available | |

4 |
<tbody> </tbody> | 2 | m | hold | |

5 |
<tbody> </tbody> | 2 | m | arrive | |

6 |
<tbody> </tbody> | 2 | m | hold | |

7 |
<tbody> </tbody> | 2 | m | hold | |

8 |
<tbody> </tbody> | 2 | m | available | |

<tbody>

</tbody>

I am trying to find the average time between all instances of arrive-hold and arrive-available for each unit (average time on hold for each unit for each event). For example, I would want to calculate the difference between row 3 and 4, and row 5 (because it is the first hold instance) and 7. Sometimes units have multiple/varying amounts of hold time stamps before they are marked arrive (as in rows 5 and 6). So the formula would have to look for the first hold time stamp, then look for the next closest arrive or available time stamp AND make sure the unit and event number match.

My timestamps are in epoch seconds. I am using Excel 2010 64-bit.

Thank you!!