Thread: Time conversion
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default Time conversion

Hi

Where to start... Time is the decimal part of datetime -and your first line
of code hides decimals.

Please do some reading at
http://www.cpearson.com/excel/datetime.htm#SerialDates
and suddenly this will make some sense:

Sub test()
MsgBox Format(62 / 24 / 60, "hh:mm:ss")
End Sub

Also, it's not obvious what your code is supposed to do, so suggesting
improvements is very difficult.

HTH. Best wishes Harald

"Stuart" skrev i melding
...
The following code gives an integer answer representing
minutes:

For Each C In .Range("B5:AF310")
With C
.NumberFormat = "0"
.Value = (Range("A" & C.Row).Value * 60) / _
(Cells(3, C.Column).Value / 60)
.Value = Round(C.Value, 0)
End With
Next

Problem: when the value is 59, I cannot find a 'nice' way to display as
hours and minutes (eg 62 should display
as 1:02)

but I am using this:
If .Value 59 And .Value < 120 Then
i = .Value - 60
If i < 10 Then
.NumberFormat = "General"
strA = "1:0" & i
C.Value = strA
Else
.NumberFormat = "General"
strA = "1:" & i
C.Value = strA
End If
End If

Is there a better way, please?

Regards.