The Excel TEXT Function
Basic DescriptionThe Excel TEXT function converts a supplied value into text, in a user-specified format.The format of the function is: TEXT( value, format_text )
and the arguments are described in the table below:
The format definitions that can be used in the Excel TEXT function are shown in the table below. Note that these definitions are also used with the 'Custom' option of Excel Cell Formatting. However, some of the options that can be used for cell formatting (eg. different text colour for positive and negative numbers) don't work in the TEXT function.
Example 1One of my most common uses of the Excel TEXT function is to incorporate dates into text strings.For example, in the spreadsheet below, if I want to join together a name and a date of birth, using the simple & operator will not give me the result I want. This is shown in the spreadsheet below, in which cell C2 uses the simple formula
=A2 & " " & B2
to join together the name in cell A2 and the date of birth in cell B2:
This result is returned because Excel is showing the underlying value of cell B2 which is an integer. (See the page on Excel Dates and Times for a further explanation of this). In order to show the name, followed by the date of birth, we need to request the value of B1 to be formatted as a date. This can be done using the Excel TEXT function, as shown in the example below. The first spreadsheet shows the formula and the lower spreadsheet shows the result.
Example 2The examples below show use the TEXT function, with a variety of specified formats. The spreadsheet on the left shows the function formats and the spreadsheet on the right shows the results.
Note that the results of the TEXT functions (shown in the above example) are all text values, rather than numeric values in Excel. This is seen by the alignment to the left of the cells (when the cell horizontal alignment is set to the default setting, "General"). Where did I go wrong?
Common Problem
You get the error message #NAME? Possible Reason This is frequently caused by a failure to encase the formatting definition in quotes. For example, the formula
=TEXT( A2, dd/mm/yyyy )
will result in the #NAME? error. Solution: Add quotes around the formatting definition. Eg. the above example would be corrected as follows:
=TEXT( A2, "dd/mm/yyyy" )
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
Copyright © 2008-2010 ExcelFunctions.net |
