I have a userform which automatically generates the current datetime and places it in a cell (end of a batch). The userform is then used again at a later time and it will repeat the step but place it in a different cell (Start of new batch). 

I want to calculate the time difference between the two datetimes in minutes. The code I am using now is giving me strange negative answers for some reason when I subtract the early datetime from later datetime so there must be an error in it somewhere. (These dates may or may not be on the same day due to starting and ending batches after midnight). 

When I simply try to subtract the two (without code) just using a cell formula I get an incorrect value of .05.

[![enter image description here](https://i.stack.imgur.com/myhoq.jpg)](https://i.stack.imgur.com/myhoq.jpg)

Does anyone know a way that I can have excel recognize these datetimes properly and subtract them so that minutes difference will be generated?

```
If opt1.Value = True And Range("U40") = "" Then
    Range("U40") = Format(txt1, "dd-mmm-yyyy hh:mm")
    UserForm3.Hide
ElseIf opt1.Value = True And Range("U41") = "" Then
    Range("U41") = Format(txt1, "dd-mmm-yyyy hh:mm")
    UserForm3.Hide
ElseIf opt1.Value = True And Range("U42") = "" Then
    Range("U42") = Format(txt1, "dd-mmm-yyyy hh:mm")
    UserForm3.Hide
ElseIf opt2.Value = True And Range("W40") = "" Then
    Range("W40") = Format(txt1, "dd-mmm-yyyy hh:mm")
    UserForm3.Hide
ElseIf opt2.Value = True And Range("W41") = "" Then
    Range("W41") = Format(txt1, "dd-mmm-yyyy hh:mm")
    UserForm3.Hide
ElseIf opt2.Value = True And Range("W42") = "" Then
    Range("W42") = Format(txt1, "dd-mmm-yyyy hh:mm")
    UserForm3.Hide
End If

If Range("U42") > "" And Range("W42") > "" Then
    Range("Y42") = Range("W42") - Range("U42")
ElseIf Range("U41") > "" And Range("W41") > "" Then
    Range("Y41") = Range("W41") - Range("U41")
ElseIf Range("U40") > "" And Range("W40") > "" Then
    Range("Y40") = Range("W40") - Range("U40")
End If

```