Вы находитесь на странице: 1из 8

Text Manipulation

When you import data from external sources or need to modify a workbook created
by someone else, the data may not be structured in a way that meets your needs. For
example, data might import into one column instead of multiple columns, which would
facilitate sorting and filtering at deeper levels. Furthermore, external data might be in all
capital letters, and you want to display the data in title case—text in which the first letter
of each major word is capitalized but prepositions such as in and on are lowercase—so
that the data are easier to read. Excel contains features to help you manipulate text to fit
your needs.
In this section, you will learn how to separate text stored in one column into multiple
columns. In addition, you will use some text functions to manipulate text in a worksheet.

Converting Text to Columns


STEP 1 Whether you use someone else’s workbook or import data from external sources, data
might be displayed in one column when they would be more useful if separated into
two or more columns. For example, a column might contain titles, first names, and last
names, such as Mr. John Doe. You want to sort the list alphabetically by last name, but
you cannot do that when the first and last names are combined in the same cell. You can
use the Text to Columns command to split the contents in one column into separate col-
umns. Figure 10.16 shows combined data in column A and the results after converting
text into three columns. The Convert Text to Columns Wizard is very similar to the Text
Import Wizard.

Excel 2016, Windows 10,


Microsoft Corporation
FIGURE 10.16 Combined and Separated Data

To convert combined text into multiple columns, complete the following


steps:
1. Select the column containing the text you want to separate.
2. Click the Data tab and click Text to Columns in the Data Tools group.
3. Use the Convert Text to Columns Wizard to distribute the data. Specify the file type,
such as Delimited or Fixed width, and click Next.
4. Specify the delimiters, such as a Tab or Space, in the Convert Text to Columns
Wizard—Step 2 of 3. The data shown in Figure 10.16 are delimited by spaces. The
wizard can use the space to separate the title and first and last names in this example.
Click Next.
5. Select the column data format, such as Text, in the Convert Text to Columns Wizard—
Step 3 of 3, and click Finish.

TIP: ALLOW ROOM FOR SEPARATION


Allow enough columns to the right of the column containing text to separate to avoid overwriting data.
Excel does not insert new columns. It separates data by placing them into adjoining columns. If you have
a first name, middle name, and last name all in one column and you separate to get a first name column,
middle name column, and last name column, you must have two empty columns. If the columns on the
right side of the original column to split are not empty, Excel will overwrite existing data.

630 Chapter 10 • Imports, XML, and Power Add-Ins

M11_GRAU9446_01_SE_E10.indd 630 2/11/16 8:37 AM


Manipulating Text with Functions
Excel has 27 functions that are specifically designed to change or manipulate text
strings. The Function Library group on the Formulas tab contains a Text command that,
when clicked, displays a list of text functions. You can also access the text functions from
the Insert Function dialog box. Some of the most commonly used text functions are
CONCATENATE, PROPER, UPPER, LOWER, and SUBSTITUTE.

Combine Text with the CONCATENATE Function


Text labels are often called text strings. A text string is not used for calculation. You can
combine text strings stored in two or more cells into one cell. For example, you might
want to combine a last name (e.g., Doe) and first name (e.g., John) stored in two cells
into one text string to look like this: Doe, John. In this example, a comma and a space are
placed after the last name. The CONCATENATE function joins between 2 and 255 indi-
vidual text strings into one text string. In Figure 10.17, the first name is in cell B2, the
last name is in cell C2, and cell E2 contains the =CONCATENATE(C2,", ",B2) function.
The comma and space included inside quotes produce Doe, John. When constructing a
CONCATENATE function, place any text (such as commas and spaces) correctly within
quotation marks so that you get the desired result. The text items can be strings of text,
numbers, or single-cell references.
=CONCATENATE(text1,text2)

Excel 2016, Windows 10,


FIGURE 10.17 Concatenation: Join Text Strings Microsoft Corporation

TIP: ANOTHER WAY TO CONCATENATE


Use the ampersand (&) operator instead of the CONCATENATE function to join text items. For
example, =A4&B4 returns the same value as =CONCATENATE(A4,B4).

Change Text Case with Text Functions


STEP 2 Data come in a variety of case or capitalization styles, such as ALL CAPS, Title Case, and
lowercase. Depending on your usage of data, you may need to change the case in a work-
sheet. Excel contains three functions to change the case or capitalization of text: PROPER,
UPPER, and LOWER. Figure 10.18 illustrates the results of these three functions.
Excel 2016, Windows 10,
Microsoft Corporation

FIGURE 10.18 Results of Text Functions

Text Manipulation • Excel 2016 631

M11_GRAU9446_01_SE_E10.indd 631 2/11/16 8:37 AM


Large amounts of capitalized text are difficult to read. Use the PROPER function to
capitalize the first letter of each word in a text string, including the first letter of preposi-
tions (such as of ) and articles (such as a). The PROPER function converts all other letters
to lowercase. The text argument is a text string that must be enclosed in quotation marks,
a formula that returns text, or a reference to a cell that contains text that you want to
partially capitalize. In Figure 10.18, cell B2 contains =PROPER(A2) to change the case
of the content in cell A2 to proper case, such as John Doe.
=PROPER(text)
The UPPER function converts text strings to uppercase letters. The text argument is
the text to be converted to all capitals and can be a reference or text string. Use this func-
tion to convert text in a cell or a range to all uppercase letters. In Figure 10.18, cell C2
contains =UPPER(A2) to change the case of the contents in cell A2 to uppercase letters,
such as JOHN DOE.
=UPPER(text)
The LOWER function converts text in a cell or range to all lowercase. In Figure 10.18,
cell D2 contains =LOWER(A2) to change the case of the text in cell A2 to lowercase let-
ters, such as john doe.
=LOWER(text)

Use the Substitute Function


Step 3 The SUBSTITUTE function substitutes, or replaces, new text for old text in a text string.
For example, if a company changes its name, you can use the SUBSTITUTE function to
replace the old company name with the new company name.
=SUBSTITUTE(text,old_text,new_text,instance_num)
Text is the original text or reference to a cell that contains the characters to be sub-
stituted, old_text is the text to be replaced, and new_text is the text you want to replace
old_text with. Instance_num specifies which occurrence of old_text you want to replace
with new_text. When instance_num is specified, only that instance is changed. If you do
not include instance_num, all occurrences are changed.

Use Other Text Functions


Step 4 Other text functions help you achieve a variety of text manipulations. Table 10.1 lists a
few other common text functions and their descriptions.

Table 10.1  Additional Text Functions


Function Description
Removes leading and trailing spaces in a text string but
TRIM(Text)
maintains spaces between words in a text string
Returns the specified number of characters from the start
LEFT(Text,Num_chars)
of a text string
Pearson Education, Inc.

Returns the specified number of characters from the end


RIGHT(Text, Num_chars)
of a text string
Returns the specified number of characters from the
MID(Text,Start_num,Num_chars) middle of a text string, based on a starting position and
number of characters

632 Chapter 10 • Imports, XML, and Power Add-Ins

M11_GRAU9446_01_SE_E10.indd 632 07/04/16 4:04 PM


TIP: NESTED TEXT FUNCTIONS
Text functions are often used in nested functions. You can nest text functions, such as
nesting the CONCATENATE function inside an UPPER function argument. For example,
=UPPER((CONCATENATE(A2,", ",A3)) concatenates the contents of cells A2, a comma and a
space, and the contents of cell A3. The concatenated result is then converted to uppercase.

Using Flash Fill


STEP 5 Flash Fill is a productivity feature that enables you to enter data in one or two cells to
provide a pattern which is used by Excel to complete the data entry. Often, you use Flash
Fill in conjunction with data in existing columns. Flash Fill has the ability to separate text
into multiple columns, combine text into one column, automatically complete text or
dates, automatically format phone numbers, and match any additional user defined pat-
terns as long as the data is structured in a similar way for Flash Fill to recognize data pat-
terns. For example, in Figure 10.19, column A contains cities and state abbreviations.
Instead of using Text to Columns, you can type the first city name in a column adjacent
to the dataset and use Flash Fill to create a column of city names only.

To use Flash Fill, complete the following steps:


1. Enter data that use part of existing data in a column in the dataset.
2. Press Enter and start typing the second sample data.
3. Click Fill on the home tab and select Flash Fill.

TIP: FLASH FILL SHORT CUT


In Excel, many features can be activated through the Ribbon or through a keyboard command
shortcut. To activate Flash Fill after providing a sample pattern, press Ctrl+E on your keyboard.

If you type only one sample entry and leave that as the active cell, you can click Fill
in the Editing group on the Home tab and select Flash Fill to complete the rest of the col-
umn. If Excel can detect a pattern, it will fill in the data in the rest of the column.

Excel 2016, Windows 10, Microsoft Corporation


Data entered to set
the text pattern
Select to Flash Fill
remainder of the column
Rest of column filled in
Original data in column A

FIGURE 10.19 Flash Fill Results

Quick
Concepts 4. What is the purpose of the Text to Columns feature? Provide one example of when it
✔ would be useful. p. 630
5. What is the difference among the PROPER, UPPER, and LOWER functions? p. 632
6. How can Flash Fill be used to replace text functions such as PROPER? p. 633

Text Manipulation • Excel 2016 633

M11_GRAU9446_01_SE_E10.indd 633 7/5/16 9:05 PM


Hands-On Exercises Watch the Video
for this Hands-
On Exercise!
HOE2 Training

Skills covered: Convert Text


to Columns • Change Text Case 2 Text Manipulation
with Text Functions • Use the
SUBSTITUTE Function • Use Other After importing the broker information, you want to use text functions to manipulate the text within the
Text Functions • Use Flash Fill worksheet. You want to make the data easier to access and display in multiple formats for future usage.

Step 1 CONVERT TEXT TO COLUMNS


Currently, the Broker Information worksheet contains the broker’s first and last name in the same column. You want to separate
the names so you can sort or filter by last name in the future. You also want to separate City and State information for the same
purpose. Refer to Figure 10.20 as you complete Step 1.

Step c: Click Text to Columns Step j: Copy and paste data

Step f: Add Last Name column heading


Excel 2016, Windows 10, Microsoft Corporation
FIGURE 10.20 Separated into Columns

a. Open e10h1Commodities_LastFirst if you closed it at the end of Hands-On Exercise


1 and save it as e10h2Commodities_LastFirst, changing h1 to h2. Click the
e10h1Broker_Information worksheet tab.
b. Select column C, right-click, and then select Insert.
You inserted a new column to place the results of separating the first and last names.
c. Select the range B1:B6, click the Data tab, and then click Text to Columns in the
Data Tools group.
The Convert Text to Columns Wizard dialog box opens.
d. Ensure Delimited is selected and click Next.
The broker names are separated with a space that will be used as a delimiter.
e. Deselect the Tab check box, click the Space check box to select it, and then click
Finish.
Once completed, first names appear in column B and last names appear in column C.
f. Click cell B1 and type First Name. Click cell C1 and type Last Name.
g. Select the range E1:E6 and click Text to Columns in the Data Tools group.
The Convert Text to Columns Wizard dialog box opens.
h. Ensure Delimited is selected and click Next.

634 Chapter 10 • Hands-On Exercise 2

M11_GRAU9446_01_SE_E10.indd 634 2/11/16 8:37 AM


i. Deselect the Space check box, click the Comma check box to select it, and then click
Finish.
Unlike broker information, the City and State information is separated by commas.
j. Select the range A1:F6, which contains the broker information. Copy the data and paste
them starting in cell I1.
Before continuing to the next step, you copied the data for future reference in this
exercise.
k. Press Esc and save the workbook.

Step 2 USE THE PROPER FUNCTION


You want to improve the readability of the broker first and last names by displaying the data in title case using the PROPER
function. Refer to Figure 10.21 as you complete Step 2.

Step c: PROPER function in Formula Bar Step b: Click to display list of Text functions

Step d: Fill Handle used to complete columns


Excel 2016, Windows 10, Microsoft Corporation
FIGURE 10.21 PROPER Function Results

a. Select the range B2:C6 and press Delete.


b. Click cell B2. Click the Formulas tab, click Text in the Function Library group, and
then select PROPER.
The Function Arguments dialog box opens.
c. Click cell J2 to enter it in the Text box and click OK.
The results of the PROPER function return the proper case of JULIUS as Julius.
d. Use the fill handle to copy the formula down and then over to complete the fill in
range B2:C6.
Using the fill handle copies the formula to complete the first and last name columns.
e. Save the workbook.

Step 3 USE THE SUBSTITUTE FUNCTION


You received a recent email that broker Christy Wilks has recently married and her last name is now Davis. You could manually
change the name; however, you have decided to practice by using the SUBSTITUTE function, as it can be used to replace large
amounts of data as well. Refer to Figure 10.22 as you complete Step 3.

Hands-On Exercise 2 635

M11_GRAU9446_01_SE_E10.indd 635 2/11/16 8:37 AM


Step b: Click to display list of Text functions

Step e: SUBSTITUTE function results


Excel 2016, Windows 10, Microsoft Corporation
FIGURE 10.22 SUBSTITUTE Function Results

a. Click cell C3 and press Delete.


b. Click Text in the Function Library group and select SUBSTITUTE.
The Function Arguments dialog box opens so that you can specify the arguments for the
SUBSTITUTE function.
c. Click cell K3 to enter it in the Text box.
d. Press Tab and type WILKS in the Old_text box.
e. Press Tab and type Davis in the New_text box and click OK
You are replacing her prior last name with her married name Davis.

TROUBLESHOOTING:  Note that the SUBSTITUTE function is case sensitive. Because you are
referencing WILKS in cell K3, it must be entered exactly the same in the function.

f. Click the warning box that appears next to cell C3 and click Ignore Error.
The warning box appears because cell C3 no longer contains the PROPER function that
is used in the rest of the column. This was done on purpose; therefore it is OK to ignore
the warning message.
g. Save the workbook.

Step 4 USE OTHER TEXT FUNCTIONS


In step 1 you separated city and state into two columns. You have decided to further separate the data by removing the zip code
from the state column. There are several methods that could be used to complete this task and you have chosen to use the LEFT
function. Refer to Figure 10.23 as you complete Step 4.

Step b: Click to display list of Text functions Step d: LEFT function results Step c: Select original text

Step e: Fill handle used to complete the column


Excel 2016, Windows 10, Microsoft Corporation
FIGURE 10.23 Use Other Text Functions

636 Chapter 10 • Hands-On Exercise 2

M11_GRAU9446_01_SE_E10.indd 636 2/11/16 8:37 AM


a. Select the range F2:F6 and press Delete.
b. Click cell F2, click Text in the Function Library group, and then select LEFT.
The Function Arguments dialog box opens so that you can specify the arguments for the
LEFT function.
c. Click cell N2 to enter it in the Text box.
d. Press Tab, type 3 in the Num_chars box, and then click OK.
The LEFT function displays the leading space and first two characters of the data in
cell N2.
e. Double-click the fill handle in cell F2 to copy the function down completing column F.
f. Save the workbook.

Step 5 USE FLASH FILL


While you have been using text functions, you want to experiment with using Flash Fill to add the zip code information. Refer to
Figure 10.24 as you complete Step 4.

Step c: Special format applied

Excel 2016, Windows 10, Microsoft Corporation


FIGURE 10.24 Final Results

a. Click cell O1, type Zip Code, and press Enter.


b. Type 06907 and press Ctrl+Enter.
c. Click the Home tab. Click the Number Format Dialog Box Launcher, click Special,
select Zip Code, and then click OK.
You apply the zip code special format to ensure the zip codes display properly.
d. Click Fill in the Editing group and select Flash Fill.
Flash fill completes the column by adding the remaining zip codes.
e. Select the range O1:O6 and click Copy in the Clipboard group.
f. Click cell G1 and click Paste in the Clipboard group.
This copies the edited data to the correct location in the workbook.
g. Select the range A1:G6. Click Copy, click the Paste arrow in the Clipboard group, and
then select Values.
This copies the data and pastes it in the same location without the underlying functions.
h. Press Esc, select the range I1:O6, and then press Delete.
i. Save the workbook. Keep the workbook open if you plan to continue with the next
Hands-On Exercise. If not, close the workbook and exit Excel.

Hands-On Exercise 2 637

M11_GRAU9446_01_SE_E10.indd 637 2/11/16 8:37 AM

Вам также может понравиться