Text function

nk18

Board Regular
Joined
Feb 4, 2005
Messages
53
Hello,

I am trying to format a number as text using the TEXT function. The problem I have is I want to format it in the following way (the brackets are just notes by the way!):

[h] (a number in hours) "h" (the letter "h"): mm (a number in minutes) m (the letter "m")

The desired result would be 12h:30m.

However, the TEXT function treats the "h" and "m" as numbers, so the above example would be:

1212:3030

Does anyone know the correct syntax to acheive this?

Thanks in advance.

PS
I need to use the TEXT function and not just custom number formats.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi, I had a similar problem the other day. You have to actualy put your h and m in "" as you have on this board. It will treat them as text then.
Dan
 
Upvote 0
Hello again,

Thanks for both of the replies.

Dan, I tried using "", however, as the TEXT function needs the "" anyway for number formats I would get an error.

Richard, that works perfectly. Would you mind explaining what the "\" does or is any information located in the help file about it? I only ask as I would like to have a leading minus sign if the number is below zero (this is the reason I am using the TEXT function as it can appear to display time as negative).

Thanks again for the help.
 
Upvote 0
Hi

The backslah is an 'escape' character that means Excel doesn't try to interpret the following character as a formatting element (otherwise you could never include # or 0 or h or m in the formatted text that is produced. I'm not aware of information on this being in the Help file (may be wrong on this) - I have Barry Houdini to thank for introducing me to the backslash in the Text function.

I think Dan was referring to a custom number format rather than in the actual TEXT function itself.

Richard
 
Upvote 0
Hi Richard,

Thanks for the explanation that's solved my problem. To get a leading minus I just put "\-h\h:mm\m". Have a nice day and thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top