Are there 2 cells that have a time in them? you could just make this a simple formula. A1 is time in, B1 is time out. This is my C1 formula.
=If(U4="O","",INT(B1-A1) * 24 + HOUR(B1-A1) + MINUTE(B1-A1)/60)
This can also be done with code. Modify this to suit your needs:
Code:
Dim wsThisSheet As Worksheet, dDifDate As Date, fTimeWorked As Double
Set wsThisSheet = ActiveWorkbook.ActiveSheet
With wsThisSheet
'Only process valid dates when U4 is not an upper or lower case O
If IsDate(.Range("A1").Value) And IsDate(.Range("B1").Value) And UCase(.Range("U4").Value) <> "O" Then
'This allows time in and time out to be reversed yet still calculate right
If .Range("B1") < .Range("A1") _
Then dDifDate = .Range("A1").Value - .Range("B1").Value _
Else dDifDate = .Range("B1").Value - .Range("A1").Value
.Range("C1").Value = Int(dDifDate) * 24 + Hour(dDifDate) + Minute(dDifDate) / 60
End If
End With