11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 20: Creating Megaformulas 559<br />

Figure 20-3 shows the results of the more conventional solution, which requires six intermediate<br />

formulas, as shown in Table 20-2. The names are in column A; column H displays the end result.<br />

Columns B-G hold the intermediate formulas.<br />

Figure 20-3: Removing the middle names and initials requires six intermediate formulas.<br />

You can access the workbook for removing middle names and initials on the companion<br />

CD-ROM. The filename is no middle name.xlsx.<br />

Table 20-2: Intermediate <strong>Formula</strong>s in the First Row of Sheet1 in Figure 20-3<br />

Cell Intermediate <strong>Formula</strong> What It Does<br />

B1 =TRIM(A1) Removes excess spaces<br />

C1 =FIND(“ “,B1) Locates the first space<br />

D1 =FIND(“ “,B1,C1+1) Locates the second space, if any<br />

E1 =IFERROR(D1,C1) Uses the first space if no second space exists<br />

F1 =LEFT(B1,C1–1) Extracts the first name<br />

G1 =RIGHT(B1,LEN(B1)–E1) Extracts the last name<br />

H1 =F1&” “&G1 Concatenates the two names<br />

Note that cell E1 uses the IFERROR function, which was introduced in Excel 2007. For compatibility<br />

with earlier versions, use this formula:<br />

=IF(ISERROR(D1),C1,D1)<br />

Notice that the result isn’t perfect. For example, it will not work if the cell contains only<br />

one name (for example, Enya). And, this method also fails if a name has two middle<br />

names (such as John Jacob Robert Smith). That occurs because the formula simply<br />

searches for the second space character in the name. In this example, the megaformula<br />

returns John Robert Smith. Later in this chapter, I present an array formula method to<br />

identify the last space character in a string.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!