Convert Time to Text

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
 
R

Rick Rothstein

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)
 
J

joeu2004

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top