Excel 2010 Bible

(National Geographic (Little) Kids) #1

232


Part II: Working with Formulas and Functions


Two functions come into play when dealing with character codes: CODE and CHAR. These func-
tions may not be very useful by themselves, but they can prove quite useful in conjunction with
other functions. I discuss these functions in the following sections.

The CODE function .......................................................................................

The Excel CODE function returns the character code for its argument. The formula that follows
returns 65, the character code for uppercase A:

=CODE(“A”)

If the argument for CODE consists of more than one character, the function uses only the first char-
acter. Therefore, this formula also returns 65 :

=CODE(“Abbey Road”)

The CHAR function .......................................................................................

The CHAR function is essentially the opposite of the CODE function. Its argument should be a value
between 1 and 255, and the function returns the corresponding character. The following formula,
for example, returns the letter A:

=CHAR(65)

To demonstrate the opposing nature of the CODE and CHAR functions, try entering this formula:

=CHAR(CODE(“A”))

This formula, which is illustrative rather than useful, returns the letter A. First, it converts the char-
acter to its code value ( 65 ), and then it converts this code back to the corresponding character.

Assume that cell A1 contains the letter A (uppercase). The following formula returns the letter a
(lowercase):

=CHAR(CODE(A1)+32)

This formula takes advantage of the fact that the alphabetic characters all appear in alphabetical
order within the character set; lowercase letters follow uppercase letters (with a few other charac-
ters tossed in between). Each lowercase letter is exactly 32 character positions higher than its cor-
responding uppercase letter.
Free download pdf