0% found this document useful (0 votes)
41 views

Text Based Functions

This chapter discusses text functions in Excel that can manipulate and analyze string values. It introduces the CONCATENATE function, which joins multiple text values into a single cell. CONCATENATE can combine text from different cells and allow characters to be placed between the concatenated parts. Other functions covered in the chapter include EXACT, FIND, FIXED, LEN, LOWER, MID, PROPER, RIGHT, SUBSTITUTE, TRIM, and UPPER, which can modify text values in various ways like changing case, extracting substrings, finding/replacing text, and more. The chapter provides an overview of many common text functions in Excel.

Uploaded by

baisakhi bhunia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Text Based Functions

This chapter discusses text functions in Excel that can manipulate and analyze string values. It introduces the CONCATENATE function, which joins multiple text values into a single cell. CONCATENATE can combine text from different cells and allow characters to be placed between the concatenated parts. Other functions covered in the chapter include EXACT, FIND, FIXED, LEN, LOWER, MID, PROPER, RIGHT, SUBSTITUTE, TRIM, and UPPER, which can modify text values in various ways like changing case, extracting substrings, finding/replacing text, and more. The chapter provides an overview of many common text functions in Excel.

Uploaded by

baisakhi bhunia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

19 0789729539 CH15 8/21/03 4:41 PM Page 325

CHAPTER
15
Text Functions

In this chapter
Text Functions Overview 326
CONCATENATE 328
EXACT 329
FIND 330
FIXED 331
LEN 332
LOWER 333
MID 334
PROPER 335
RIGHT 336
Add st, nd, rd, and th to the End of Numbers 337
SUBSTITUTE 338
TRIM 339
UPPER 340
19 0789729539 CH15 8/21/03 4:41 PM Page 326

326 Chapter 15 Text Functions

Text Functions Overview


Text functions can be used in several ways. They can return the number of characters in text
15 strings, remove extra spaces and nonprintable characters from cells, return exact data within
a string, change the case of text strings, and even combine text from other cells. If you
inherit workbooks from other people, you will eventually have to clean up or manipulate the
data. Text functions allow you to create consistency throughout the workbook. Because cer-
tain functions are case sensitive, it’s good practice to create consistency throughout lists and
tables. This chapter covers the functions in Table 15.1 that are marked in bold.

Table 15.1 Text Functions


Function Syntax Description
CHAR =CHAR(number) Returns the character specified by a number.
CLEAN =CLEAN(text) Removes all nonprintable characters from
text.
CODE =CODE(text) Returns a numeric code for the first
character in a text string.
CONCATENATE =CONCATENATE(text1,text2,...) Joins several text strings into one text string.
DOLLAR =DOLLAR(number,decimals) Converts a number to text using currency
format, with the decimals rounded to the
specified place.
EXACT =EXACT(text1,text2) Compares two text strings and returns
TRUE if they’re exactly the same, and
FALSE otherwise.
FIND =FIND(find_text,within_text, Finds one text string within another text
start_num) string, andreturns the number of the
starting position of find_text, from the
leftmost character of within_text.
FIXED =FIXED(number,decimals, Rounds a number to a specified number of
no_commas) decimals, formats the number in decimal
format using a period and commas, and
returns the result as text.
LEFT =LEFT(text,num_char) Returns the first character or characters in a
text string based on the number of characters
you specify.
LEN =LEN(text) Returns the number of characters in a text
string.
LOWER =LOWER(text) Converts all uppercase letters in a text string
to lowercase.
19 0789729539 CH15 8/21/03 4:41 PM Page 327

Text Functions Overview 327

Function Syntax Description


MID =MID(text,start_num,num_char) Returns a specific number of characters from
a text string, starting at the position you 15
specify.
PROPER =PROPER(text) Capitalizes the first letter of each word in a
text string and any other letters in text that
follow any character other than a letter.
REPLACE =REPLACE(old_text,start_num, Replaces a portion of a text string with a
num_chars,new_text) different text string based on the number of
characters you specify.
REPLACEB =REPLACEB(old_text,start_num, Replaces part of a text string with a
num_bytes,new_text) different text string based on the number of
bytes you specify.
REPT =REPT(text,number_times) Repeats text a given number of times.
RIGHT =RIGHT(text,num_chars) Returns the last character or characters in a
text string based on the number of characters
you specify.
SEARCH =SEARCH(find_text, Returns the number of the character at
within_text, start_num) which a specific character or text string is
first found, reading from left to right.
SEARCH is not case sensitive and can include
wildcard characters.
SEARCHB =SEARCHB(find_text, Returns the number of the character at
within_text,start_num) which a specific haracter or text string is
first found, based on its byte position,
reading from left to right.
SUBSTITUTE =SUBSTITUTE(text,old_text, Substitutes new_text for old_text in a T
new_text,instance_num) text string. Returns the text referred to by
=T(value) value.
TEXT =TEXT(value,format_text) Converts a value to text in a specific number
format.
TRIM =TRIM(text) Removes all spaces from text except for
single spaces between words.
UPPER =UPPER(text) Converts text to uppercase.

VALUE =VALUE(text) Converts a text string that represents a


number to a number.
19 0789729539 CH15 8/21/03 4:41 PM Page 328

328 Chapter 15 Text Functions

CONCATENATE
The CONCATENATE function is one of the more useful functions you’ll find in Excel. CONCATE-
15 NATE can be used to join text in several forms. One reason it’s useful is when you inherit
spreadsheets from other creators you’ll often need to clean up the cells and text. Often, this
includes the combination of information within one cell and this is where concatenate
comes in.
=CONCATENATE(text1,text2,...)

Using this function by itself joins a city and state as shown in the first example in Fig-
ure 15.1; however, you also can place characters between the adjoined text by inserting them
within a pair of open and close quotation marks.

N OTE
If you adjoin numbers with the ampersand or the CONCATENATE function, the result is
converted to text.

The characters or text can include spacing, dashes, commas, numbers, other functions, and
so on. Notice some of the different ways the CONCATENATE function can join text in separate
cells. You can also use the ampersand (&). If you want to adjoin three or more cells with the
ampersand, it would appear as follows: =A1&B1&C1. If you want to separate the three cells
with a space, it would be =A1&” “&B1&” “&C1. Notice how each adjoined cell or text is sepa-
rated by the ampersand.
■ TEXT 1, TEXT 2...—Text is the text to be joined. You can join from 1 to 30 items
per cell.

TIP FROM
Using & to connect strings does NOT have CONCATENATE’s 30-item limit.
19 0789729539 CH15 8/21/03 4:41 PM Page 329

EXACT 329

Figure 15.1
The CONCATE-
NATE function
allows you to join 15
text from separate
cells into the same
cell.

Ampersand joins text with next characters


Quotes allow for text insertion

EXACT
EXACT compares two text strings and returns TRUE if they’re exactly the same, and FALSE
otherwise. EXACT is case sensitive.
=EXACT(text1,text2)

The EXACT function compares two text strings to see whether they are the same. The EXACT
function can operate from text within the function or via cell referencing. The EXACT func-
tion is case sensitive as shown in the following examples.
■ TEXT 1, TEXT 2...—The text is the first text string and then the second text string.

For example:
=EXACT(“BILL”,”bill”) results in FALSE.
=EXACT(“BILL”,”BILL”) results in TRUE.

As you see in Figure 15.2, there are two examples comparing ranges of cells with the EXACT
function. The first displays TRUE when an asset is complete using cell referencing. The
second compares a single cell reference to a range in the form of an array. If you had a list of
assets, and all assets had unique identities, you might want to determine whether the asset is
in the list. For this, you would use the EXACT function with the OR function in the form of an
array as shown here and in cell F16 of Figure 15.2. Be sure to activate the array by pressing
Ctrl+Shift+Enter.
ARRAY {=Or(Exact(Cell Reference, Compare Range))}
19 0789729539 CH15 8/21/03 4:41 PM Page 330

330 Chapter 15 Text Functions

Figure 15.2
The EXACT function
tests two sets of infor-
15 mation and displays a
logical value of TRUE
or FALSE depending Compares...
on whether the infor- ...this cell...
mation is equal. ...with this cell

Looks up a cell against a range

FIND
FIND locates one text string with another text string and returns the number of the starting
position of find_text, from the leftmost character of within_text. The FIND function is case
sensitive.
=FIND(find_text,within_text,start_num)

■ FIND_TEXT—The find_text is the text you want to locate or find.


■ WITHIN TEXT—The within_text refers to the text string you’re looking within.
■ START NUM—The start_num refers to the number from left to right from which to start
looking for the text. For example, Patrick where the “t” character would be third as the
start_num.

For example:
=FIND(“W”,”Wally Bill”), where W is the first character in the string, results in 1.
=FIND(“a”,”Wally Bill”), where a is the second character in the string, results in 2.

N OTE
It’s important to note that FIND looks only for the first instance of the text it’s looking for.
If, for example, we were looking for “a” in, “Wally Ball,” the result would still be 2.

If you had a cell that contained the names of people and the cities and states they lived in,
you could combine the FIND function with the MID function to extract a text string. The MID
function is explained later in this chapter.
19 0789729539 CH15 8/21/03 4:41 PM Page 331

FIXED 331

In Figure 15.3, the formula =Mid(C6,1,Find(“ “,C6,1)-1) results in the extraction of the
first word, which in this case is a name in the cell, regardless of the length of the first name.
The MID function (covered later in this chapter) looks at cell C6 and starts with the first text
string; the FIND function also starts with cell C6 and looks for the first space as noted in the
15
quotation marks. The formula then takes the position of the space found and subtracts 1 to
return the result.
To take this explanation a step further, the formula =Mid(C6,1,Find(“ “,C6,1)-1) extracts
the first word from a string regardless of the length of the string. The FIND function looks
for a space in the text in cell C6 beginning at character 1. It finds this space at position 6.
Then 1 is deducted from this resulting in a formula which now evaluates to this:
=Mid(C6,1,5). The MID function (covered later in this chapter) now extracts a five-character
string from cell C6 beginning at character position 1.

Looks for character Subtracts the space


number in text string and returns the result
Finds the space

Figure 15.3
The FIND function
combined with the
MID function can
extract text strings in
cells regardless of the
string length.

FIXED
The FIXED function rounds a number to a specified number of decimals, formats the num-
ber in decimal format using a period and commas, and returns the result as text:
=FIXED(number,decimals,no_commas)

The FIXED function can round numbers in a cell. You can use the FIXED function with text in
the function or with cell referencing. Use the FIXED function to round numbers to decimals,
hundreds, and thousands. The examples in Figure 15.4 round a number to decimals, tens,
hundreds, and thousands using the FIXED function.
19 0789729539 CH15 8/21/03 4:41 PM Page 332

332 Chapter 15 Text Functions

N OTE
The difference between FIXED and ROUND is that FIXED returns its answer in the form
of text. FIXED results can be used only in other numeric calculations if converted back to
15 a number using the VALUE function.

■ NUMBER—The number refers to the number you want to round or convert to text.
■ DECIMALS—The decimals refer to the number of decimal places to the right. If no deci-
mals are specified it assumes 2.
■ NO COMMAS—The no commas is a logical result in that if TRUE, it prevents the function
from including any commas in the text returned result. For example, the formula
=Fixed(2345.24,1,TRUE) would result in 2345.2 without commas.

Figure 15.4
Use the FIXED
function to round
numbers in a cell.

LEN
LEN returns the number of characters in a text string:
=LEN(text)

The LEN function on its own returns the number of characters in a text string. For example,
if you had the name Bob in cell A1 and you typed in cell B1 =LEN(A1) the result would be 3.
This is an extremely powerful tool when combined with other functions. See also, the
“RIGHT” function.
■ TEXT—The text refers to the text string, word, or multiple words that you want to find
the total number of characters. For example, the formula =LEN(“ Hello”) would result
in 5.

Because spaces also count as one character, =LEN(“Mn Albany”) would result in 9. While the
usefulness of this function may not seem clear, in reality, when combined with other
19 0789729539 CH15 8/21/03 4:41 PM Page 333

LOWER 333

functions in Excel, the LEN function becomes a powerful tool for extracting text strings. If
you work in an environment in which you have to clean workbooks that were set up
improperly, or you’ve inherited lists of information and have to extract text strings within
cells for your own particular purposes, use the LEN function in conjunction with other Excel
15
functions. In the example in Figure 15.5, say you wanted to extract the equipment brand
from the equipment type. The function =RIGHT(C17,LEN(C17)-FIND(“ “,C17)) results in
Caterpillar, because the function extracts the text to the right of the space. (See the “RIGHT”
section later in this chapter.)

Finds right-most character Looks for a space


Counts characters in cell Returns the result

Figure 15.5
Use LEN with other
functions in Excel for
text extraction.

LOWER
LOWER converts all letters in a text string to lowercase:
=LOWER(text)

The LOWER function is primarily a cleaning function. If you have inconsistent data in lists
and you want all characters to result in lowercase, use the LOWER function. In Figure 15.6,
the LOWER function converts all the uppercase names to lowercase. Use Paste Special and
paste as values back into the original location in the list after you’ve converted all charac-
ters to lowercase. This function can be used with text in a cell or with cell referencing as
demonstrated in the figure.
For more information on Paste Special See also Chapter 17, “Setting Up a List or
Database in Excel.”
■ TEXT—This is the text within the cell you want to convert to lowercase characters.
19 0789729539 CH15 8/21/03 4:41 PM Page 334

334 Chapter 15 Text Functions

Figure 15.6
Use the LOWER func-
tion to clean lists of
15 information that are
inconsistent.

MID
Use the MID function to return a specific number of characters from a text string, starting at
the position you specify:
=MID(text,start_num,num_char)

■ TEXT—The text is the text string or word you want to extract from.
■ START_NUM—The start_num is the number of the character within the text string or
word you want to extract from.
■ NUM_CHAR—The num_char is the number of characters to extract from the start_num
point to the right.

You can use text within the formula or use cell referencing. For example, =MID(“Chris”,1,4)
returns only the first four characters in the string—Chri. =MID(“Hobbe”,2,4) returns the text
string starting with the second character in the string—obbe. Combined with the FIND func-
tion, you can create a powerful tool to dynamically extract any text within a string as shown
in Figure 15.7 and described in this section. If you have a URL and you want to extract the
actual name from a list of URLs and the name appears in different locations in each URL,
you could use the following formulas to do so.
In cell C6, the formula used to extract any text name from a URL is
=MID(B6,FIND(“Sports”,B6),6)
19 0789729539 CH15 8/21/03 4:41 PM Page 335

PROPER 335

If the name doesn’t appear in the URL, it will return a #Value error. To eliminate this, use
the function found in cell C10 in Figure 15.7 and shown here:
=IF(ISERROR(FIND(“Sports”,B11)),””,MID(B11,FIND(“Sports”,B11),6)) 15

Figure 15.7
Use the MID function
as a standalone func-
tion or in combina-
tion with other
functions such as
FIND.

To set up the same formula as shown here with cell referencing, see the formula in Fig-
ure 15.7 located in cell E17 and shown here. This will allow you to dynamically pull any text
string from a URL.
=IF(ISERROR(FIND(C17,B17)),””,MID(B17,FIND(C17,B17),D17))

PROPER
PROPER capitalizes the first letter of each word in a text string or sentence.
=PROPER(text)

The PROPER function is another cleaning tool function. It places initial caps on each word
within the text string specified in the formula, or text within a cell if you are using cell refer-
encing. The result of =PROPER(“PATRICK”) would be Patrick. Notice that the example in
Figure 15.8, used with cell referencing on lists, can quickly clean up the list.
■ TEXT—The text is the text in the text string, word, or sentence to convert to proper.
Meaning, the first character is capitalized in each word.
19 0789729539 CH15 8/21/03 4:41 PM Page 336

336 Chapter 15 Text Functions

Figure 15.8
The PROPER func-
tion creates text with
15 initial caps.

RIGHT
RIGHT returns the last character or characters in a text string:
=RIGHT(text,num_chars)

The text can be in the form of text within the formula or as a cell reference. (Refer to the
“LEFT” section earlier in this chapter.) The NUM_CHARS argument is the number of characters
to return.
■ TEXT—This is the text string, word, or sentence you want to extract characters from.
■ NUM_CHARS—This indicates the number of characters you want to extract starting from
the right moving left.

For example, =RIGHT(“Patrick”,4) would return rick, as shown in Figure 15.9. When
including text within the formula, you need quotes. When you use cell referencing, you
don’t.
19 0789729539 CH15 8/21/03 4:41 PM Page 337

Add st, nd, rd, and th to the End of Numbers 337

Finds the space

Figure 15.9
The RIGHT function 15
in conjunction with
the LEN and FIND
functions can be used
to extract the right-
most words.

Counts
Starting at the right
characters

Add st, nd, rd, and th to the End of Numbers


You can use the IF, OR, VALUE, RIGHT, and CHOOSE functions together to create automated
ordinals, where an ordinal is an adjective used to describe the numerical position of an
object. In Figure 15.10, B7 contains the number 1. If your list of numbers begin in cell B7,
the formula would be
=B7&If(Or(Value(Right(B7,2))={11,12,13}),”th”,If(Or(Value(Right(B7))
➥={1,2,3}),Choose(Right(B7),”st”,”nd”,”rd”),”th”))

This code adds the following results to the end of ordinary numbers:
1st

2nd

3rd

4th
19 0789729539 CH15 8/21/03 4:41 PM Page 338

338 Chapter 15 Text Functions

Figure 15.10
You can add ordinals
to the end of num-
15 bers automatically.

Adds ordinals to ordinary numbers

SUBSTITUTE
The SUBSTITUTE function replaces old text within a text string with new text.
=SUBSTITUTE(text,old_text,new_text,instance_num)

The text can be in the formula or used as a cell reference. The examples in Figure 15.11
show the SUBSTITUTE function in the first example using complete cell referencing from one
cell to another. The second example gives a mix of cell referencing and text directly in the
formula. For the formula =SUBSTITUTE(“Melrose”,C11,”Farming”), where Cll equals
Melrose, the result is Farming.

■ TEXT—This is the text in a cell you want to substitute.


■ OLD_TEXT—This is the text you want to replace.
■ NEW_TEXT—This is the new text to replace the old text with.
■ INSTANCE_NUM—This is the number of instances you want to replace the old text with.
For example, if you want to replace every occurrence of old text, use “][“. If replacing
just one occurrence, use 1.
19 0789729539 CH15 8/21/03 4:41 PM Page 339

TRIM 339

Figure 15.11
The SUBSTITUTE
function replaces one
text string or cell for 15
another.

Substitute this...
...with this

TRIM
The TRIM function is another cleaning function that removes spacing between words:
=TRIM(text)

For example, if you inherit a list of information and there is random spacing between the
text at different locations, you can trim away the spacing by referencing the cell. For exam-
ple, in Figure 15.12 the left column shows a mixture of spacing. However, by applying the
TRIM function to the right, you can eliminate the spacing. Use the Paste Special command to
paste the cleaned text back into the original column as values. This function is specifically
useful when data is imported from other applications, particularly mainframe and DOS
applications, where spacing often is used as separators in lists and forms.
■ TEXT—This is the text or cell reference containing the text from which you want to
remove all the excess spaces.
19 0789729539 CH15 8/21/03 4:41 PM Page 340

340 Chapter 15 Text Functions

Figure 15.12
The TRIM function
can trim random
15 spacing from cells.

Random spaces
TRIM function cleans spaces

UPPER
Similar to the LOWER function, the UPPER function converts all text within a cell to uppercase:
=UPPER(text)

For example, =UPPER(“upper”) would result in UPPER. Cell referencing can also be used as
shown in Figure 15.13.
■ TEXT—This is the text or cell reference containing text that you want to change to
uppercase.

Figure 15.13
The UPPER function
converts all text to
uppercase.
19 0789729539 CH15 8/21/03 4:41 PM Page 341

Excel in Practice 341

Troubleshooting
Text in Formulas
When using functions such as LEFT and RIGHT, I get the #NAME? error.
If you’re placing text in formulas, enclose the text in quotation marks, such as
=RIGHT(“Bill”,2). An easier way would be to place Bill in a cell such as A1, and then the
formula could be used with cell referencing such as =RIGHT(A1,2).

Excel in Practice
By knowing which text functions do what, you can simplify your life and become extremely
efficient when it comes to managing data. Notice in Figure 15.14 that the initial list has tons
of inconsistencies. By using the following functions, you can quickly clean up and modify
this list: Notice the functions used in cells C16:F16.
■ TRIM function—Removes all the unnecessary spaces in a cell.
■ PROPER function—Creates initial caps on all text.
■ CONCATENATE function—Adjoins text from different cells.

PROPER styles initial caps

Figure 15.14
Use text functions to
quickly manipulate
poorly organized lists
of information.

TRIM removes excess spaces CONCATENATE joins text

You might also like