Time - Covert to number

R

Richard

Hi

I am working on over-time claims.
On A1 is start time, B1 is end time and C1 is sub-total
time. All cells format are [hh]:mm

Example:
A1 B1 C1
18:00 19:30 1:30

My questions
1) How to covert C1 to be 1.5 hour ISO 1:30?
2) Instead of typing 18:00, can just type 1800?

Thanks!
 
J

JohnB

Below is a Visual Basic statement that someone in this
NewsGroup gave to me a few weeks ago. I used it and I
now am able to enter the time as 0800 and have it appear
as 08:00 in cells formatted as hh:mm

You can then use a formula to subract one time from
another to calculate the duration. So 16:00 hours minus
08:00 hours will return an answer of 8 hours. Remember,
if your answer will exceed 24 hours, you must format the
answer cell as custom - [h]:mm

Should you wish to convert the answer to fractions of an
hour, format that answer cell as "number" with 1 or 2
decimal places and insert a formula that multiplies the
answer by 24. Thus an answer of 7:30 when multiplied byb
24 will return an answer of 7.5 hours.


Application.EnableEvents = False
With Target
If .HasFormula = False Then
Select Case Len(.Value)
Case 1 ' e.g., 1 = 00:01 AM
TimeStr = "00:0" & .Value
Case 2 ' e.g., 12 = 00:12 AM
TimeStr = "00:" & .Value
Case 3 ' e.g., 735 = 7:35 AM
TimeStr = Left(.Value, 1) & ":" & _
Right(.Value, 2)
Case 4 ' e.g., 1234 = 12:34
TimeStr = Left(.Value, 2) & ":" & _
Right(.Value, 2)
Case 5 ' e.g., 12345 = 1:23:45 NOT 12:03:45
TimeStr = Left(.Value, 1) & ":" & _
Mid(.Value, 2, 2) & ":" & Right(.Value, 2)
Case 6 ' e.g., 123456 = 12:34:56
TimeStr = Left(.Value, 2) & ":" & _
Mid(.Value, 3, 2) & ":" & Right(.Value, 2)
Case Else
Err.Raise 0
End Select
.Value = TimeValue(TimeStr)
End If
End With
Application.EnableEvents = True
Exit Sub
EndMacro:
MsgBox "You did not enter a valid time"
Application.EnableEvents = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top