Excel Macro to find time gaps

bamboo1975

New Member
Joined
Apr 10, 2019
Messages
11
Office Version
  1. 2013
Platform
  1. Windows
Hi, I have cells with data like below in a column. I wonder, can anyone help me with a macro to search and find any two consecutive cells with over 10 minutes difference and highlight them in yellow? Much appreciated.


05/03/2019 06:34
05/03/2019 06:57
05/03/2019 07:16
05/03/2019 07:19
05/03/2019 07:25
05/03/2019 07:29
05/03/2019 07:53
05/03/2019 07:57
05/03/2019 08:01
05/03/2019 08:05
05/03/2019 08:07
05/03/2019 08:22
05/03/2019 08:23
05/03/2019 08:23
05/03/2019 08:23
05/03/2019 08:25
05/03/2019 08:25
05/03/2019 08:26
05/03/2019 08:27
05/03/2019 08:36

<colgroup><col></colgroup><tbody>
</tbody>
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi bamboo1975,

Welcome to the MrExcel Forum.

You asked for a Macro, does this meet your requirements. The code assumes that your data begins in Cell A2 and goes down Column A.

Code:
Sub test()


    Dim tim As Range
    Dim i As Long
    
    Set tim = Range("A2", "A" & Cells(Rows.Count, 1).End(xlUp).Row + 1)
    For i = 2 To tim.Cells.Count
        If Format(tim.Cells(i, 1) - tim.Cells(i - 1), "hh:mm;@") > #12:10:00 AM# Then
            tim.Cells(i - 1).Interior.Color = RGB(255, 255, 0)
            If Not tim.Cells(i, 1) = "" Then tim.Cells(i, 1).Interior.Color = RGB(255, 255, 0)
        End If
    Next
    
End Sub
 
Upvote 0
Try this:

Code:
Sub test()
    For Each t In Range("A2", Range("A" & Rows.Count).End(xlUp))
        If t.Offset(1).Value - t.Value > TimeValue("00:10:00") Then t.Resize(2).Interior.ColorIndex = 6
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,211
Messages
6,129,528
Members
449,515
Latest member
lukaderanged

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