West
West

Reputation: 2570

How to get the value of a cell displaying time, as text, in VBA

I have cell C4 with the value 1:05:20 and I'm trying to create a string TIME 1:05:20 and paste this string into another cell C5 using VBA but am not getting what I need. My code below returns TIME 4.53703703703704E-02 instead.

Public Sub timer()

Range("C5").Value= "TIME" & " " & Range("C4").Value

End Sub

How can I get the required value?

Upvotes: 0

Views: 3088

Answers (1)

SJR
SJR

Reputation: 23081

Assuming it is a proper time you have to format it. To Excel dates and times are just numbers, it's the formatting that makes them look like dates or times. (A time is a fraction of a day, hence your answer.)

Range("C5").Value = "TIME" & " " & Format(Range("C4").Value, "hh:mm:ss")

Upvotes: 2

Related Questions