Convert Time to Text

  • Thread starter Thread starter If
  • Start date Start date
I

If

Hello,

Is it possible to convert a time to text

Example : 12:20:00 ---> 12 h 20 (texte format)

I know the procedure =TEXT ...
Is there something but in vba?

Thanks for your help.

Yves
 
Is it possible to convert a time to text
Example : 12:20:00 ---> 12 h 20 (texte format)

I know the procedure =TEXT ...
Is there something but in vba?

You can use the Format function in VBA...

YourTimeValue = #12:20:00#
MsgBox Format(YourTimeValue, "h \h mm")

Rick Rothstein (MVP - Excel)
 
If said:
Is it possible to convert a time to text
Example : 12:20:00 ---> 12 h 20 (texte format)
I know the procedure =TEXT ...
Is there something but in vba?

The VBA Format function is similar to the Excel TEXT function. For example:

Const d As Double = #12:20:00 PM#
MsgBox Format(d, "h \h m")

If 12:20:00 is in A1 (formatted any way you wish), you could also do:

=TEXT(A1, "h \h m")

And you can do:

=A1

with the Custom format "h \h m" without quotes.
 
Back
Top