Page 254 - Excel 2007 Bible
P. 254
17_044039 ch12.qxp 11/21/06 11:05 AM Page 211
Creating Formulas That Manipulate Text
Displaying formatted values as text
The TEXT function enables you to display a value in a specific number format. Figure 12.2 shows a simple
worksheet. The formula in cell D3 is
=”The net profit is “ & B3
FIGURE 12.2
The formula in D3 doesn’t display the formatted number.
This formula essentially combines a text string with the contents of cell B3 and displays the result. Note,
however, that the contents of B3 are not formatted in any way. You might want to display the contents of B3 12
using a Currency number format.
NOTE Contrary to what you might expect, applying a number format to the cell that contains the for-
NOTE
mula has no effect. This is because the formula returns a string, not a value.
Here’s a revised formula that uses the TEXT function to apply formatting to the value in B3:
=”The net profit is “ & TEXT(B3,” $#,##0”)
This formula displays the text along with a nicely formatted value:
The net profit is $230,794.
The second argument for the TEXT function consists of a standard Excel number format string. You can
enter any valid number format code for this argument.
The preceding example uses a simple cell reference (B3). You can, of course, use an expression instead.
Here’s an example that combines text with a number resulting from a computation:
=”Average Expenditure: “& TEXT(AVERAGE(A:A),”$#,##0.00”)
This formula might return a string such as Average Expenditure: $7,794.57.
Here’s another example that uses the NOW function (which returns the current date and time). The TEXT
function displays the date and time, nicely formatted.
=”Report printed on “&TEXT(NOW(),”mmmm d, yyyy at h:mm AM/PM”)
The formula might display the following:
Report printed on March 22, 2007 at 3:23 PM.
CROSS-REF Refer to Chapter 24 for details on Excel number formats.
CROSS-REF
211