ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert Time to Text (https://www.excelbanter.com/excel-programming/444774-convert-time-text.html)

If[_3_]

Convert Time to Text
 

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



Rick Rothstein

Convert Time to Text
 
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)


joeu2004[_2_]

Convert Time to Text
 
"If" wrote:
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.



All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com