Thread: Text to Time
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Text to Time

I think you need activecell.currentregion. Activerange isn't correct.


Sub TEXT_TO_TIME()
For Each cell In ActiveCell.CurrentRegion
If IsDate(cell) Then
cell.Value = TimeValue(cell)
End If
Next cell
End Sub

"build" wrote:

Thanks Joel,
But that gives a "type mismatch"
cheers


"Joel" wrote in message
...
Use the isdate function to make sure cell is date format. Error 13 is
caused
by non-date values being passed to datavalue

Sub TEXT_TO_TIME()
For Each cell In ActiveRange
if isdate(cell) then
cell.Value = TimeValue(cell)
end if
Next cell
End Sub


"build" wrote:

G'day All,
I'm very rusty with VBA.
I'm trying to convert text "1:28.871" to time "m:ss.000"
I've got:

Sub TEXT_TO_TIME()
For Each cell In ActiveRange
cell.Value = TimeValue(cell)
Next cell
End Sub

This gives me "run-time error '13':"
A google points to
"due to copied data being formatted as text rather than numbers"
but hey I know that.
Any Ideas?

Thanks in anticipation,
build