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.


[TABLE="width: 121"]
<colgroup><col></colgroup><tbody>[TR]
[TD="align: right"]05/03/2019 06:34
[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 06:57[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 07:16[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 07:19[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 07:25[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 07:29[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 07:53[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 07:57[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:01[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:05[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:07[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:22[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:23[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:23[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:23[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:25[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:25[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:26[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:27[/TD]
[/TR]
[TR]
[TD="align: right"]05/03/2019 08:36[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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,223,577
Messages
6,173,163
Members
452,503
Latest member
AM74

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