Вы можете изменить код и попробовать:
Option Explicit
Sub test()
Dim strID As String, strCourse As String, strEvent As String
Dim DateTime1 As Date, DateTime2 As Date
Dim LastRow As Long, i As Long, y As Long
With ThisWorkbook.Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 2 To LastRow
strID = .Range("A" & i).Value
strCourse = .Range("B" & i).Value
DateTime1 = CDate(.Range("C" & i).Value) & " " & CDate(.Range("D" & i).Value)
strEvent = .Range("E" & i).Value
For y = 2 To LastRow
If y <> i Then
If .Range("A" & y).Value = strID And .Range("B" & y).Value = strCourse And .Range("E" & y).Value = strEvent And .Range("F" & i).Value = "" And .Range("F" & y).Value = "" Then
DateTime2 = CDate(.Range("C" & y).Value) & " " & CDate(.Range("D" & y).Value)
.Range("F" & i).Value = Abs(DateDiff("h", DateTime2, DateTime1))
End If
End If
Next y
Next i
End With
End Sub