View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Convert timespan d:hh:mm:ss to number

Assuming the date is text, try this UDF:

Function changeit(r As Range) As Long
Dim nv As Long
s = Split(r.Value, ":")
nv = 24# * 60# * 60# * s(0)
nv = nv + 60# * 60# * s(1)
nv = nv + 60# * s(2)
nv = nv + s(3)
changeit = nv
End Function

This can also be performed directly on the worksheet, without any VBA:

=LEFT(C4,1)*24*60*60 + MID(C4,3,2)*60*60+MID(C4,6,2)*60+RIGHT(C4,2)

--
Gary''s Student - gsnu200760


"Enigo" wrote:

Hi,

I have a field that is imported from Siebel to CSV in the format d:hh:mm:ss.
I need to convert this back to seconds. I have tried changing the format of
the cells but this does not work.

Can anyone help?

Thanks