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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Dan71

New Member
Joined
Jul 31, 2006
Messages
48
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
 

nk18

Board Regular
Joined
Feb 4, 2005
Messages
53
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.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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
 

nk18

Board Regular
Joined
Feb 4, 2005
Messages
53
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.
 

Forum statistics

Threads
1,141,224
Messages
5,705,122
Members
421,378
Latest member
CarlosDuran

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
Top