You have to explicitly calculate the case where it crosses midnight. Here is one way to do it.
BTW you can directly get minutes with "n" instead of getting seconds and dividing by 60.
Private Sub CommandButton1_Click()
Dim lr As Integer
Dim dur As Long
Dim i As Long
lr = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lr
If Cells(i, 1) <= Cells(i, 2) Then
dur = DateDiff("n", Cells(i, 1), Cells(i, 2))
Else
dur = DateDiff("n", Cells(i, 1), 1) + DateDiff("n", 0, Cells(i, 2))
End If
Cells(i, 4).Value = dur
Next i
End Sub
Bookmarks