Private Sub CommandButton1_Click()
Dim i As Long, j As Long, H1, H2, D1, D2
Dim DRL As Long
With Sheets("TEST")
DRL = .Range("A400").End(xlUp).Row
H1 = CDate(TextBox1): H2 = CDate(TextBox2)
D1 = CDate(TextBox3): D2 = D1 + 1
For i = 2 To DRL
If .Cells(i, 1) = D1 Then
If H1 <= H2 Then
.Cells(i, 2) = H2 - H1
Exit For
Else
.Cells(i, 2) = 1 - H1
For j = 2 To DRL
If .Cells(j, 1) = D2 Then
.Cells(j, 2) = H2
Exit For
End If
Next j
End If
End If
Next i
End With
End Sub