Page 253 - Excel 2007 Bible
P. 253
17_044039 ch12.qxp 11/21/06 11:05 AM Page 210
Part II
Working with Formulas and Functions
This formula will return either TRUE of FALSE. However, Excel is a bit lax in its comparisons when text is
involved. Consider the case in which A1 contains the word January (initial capitalization), and A2 con-
tains JANUARY (all-uppercase). You’ll find that the previous formula returns TRUE, even though the con-
tents of the two cells are not really the same — the comparison is not case-sensitive.
Often, you don’t need to worry about the case of the text. But if you need to make an exact, case-sensitive
comparison, you can use the EXACT function. The formula that follows returns TRUE only if cells A1 and
A2 contain exactly the same entry:
=EXACT(A1,A2)
When you compare text, be careful with space characters — which are often difficult to spot. The following
formula returns FALSE because the first string contains a trailing space:
=EXACT(“Canada “,”Canada”)
Joining two or more cells
Excel uses an ampersand (&) as its concatenation operator. Concatenation is simply a fancy term that
describes what happens when you join the contents of two or more cells. For example, if cell A1 contains
the text Tucson and cell A2 contains the text Arizona, the following formula will return
TucsonArizona:
=A1&A2
Notice that the two strings are joined together without an intervening space. To add a space between the
two entries (to get Tucson Arizona), use a formula like this one:
=A1&” “&A2
Or, even better, use a comma and a space to produce Tucson, Arizona:
=A1&”, “&A2
If you’d like to force the second string to be on a new line, concatenate the strings using CHAR (10), which
inserts a line-break character. Also, make sure that you apply the Wrap Text format to the cell. The follow-
ing example joins the text in cell A1 and the text in cell B1, with a line break in between:
=A1&CHAR(10)&B1
TIP To apply Wrap Text formatting, select the cells and then use Home ➪ Alignment ➪ Wrap Text.
TIP
Here’s another example of the CHAR function. The following formula returns the string Stop by concatenat-
ing four characters returned by the CHAR function:
=CHAR(83)&CHAR(116)&CHAR(111)&CHAR(112)
Here’s a final example of using the & operator. In this case, the formula combines text with the result of an
expression that returns the maximum value in column C:
=”The largest value in Column C is “ &MAX(C:C)
NOTE Excel also has a CONCATENATE function, which takes up to 255 arguments. For example:
NOTE
=CONCATENATE(A1,B1,C1,D1)
This function simply combines the arguments into a single string. You can use this function if you like, but
using the & operator results in shorter formulas.
210