18.11.2014 Views

Microsoft Office

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

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

Creating Formulas That Manipulate Text 12<br />

Following is a modification that doesn’t use the IFERROR function. This formula works for all versions of<br />

Excel.<br />

=IF(ISERR(FIND(“ “,A1)),A1,RIGHT(A1,LEN(A1)-FIND(“*”,SUBSTITUTE(A1,<br />

” “,”*”,LEN(A1)-LEN(SUBSTITUTE(A1,” “,””))))))<br />

Extracting all but the first word of a string<br />

The following formula returns the contents of cell A1, except for the first word:<br />

=RIGHT(A1,LEN(A1)-FIND(“ “,A1,1))<br />

If cell A1 contains 2007 Operating Budget, the formula returns Operating Budget.<br />

The formula below, which uses the new IFERROR function, returns the entire contents of cell A1 if the cell<br />

doesn’t have a space character:<br />

=IFERROR(RIGHT(A1,LEN(A1)-FIND(“ “,A1,1)),A1)<br />

A modification that works in all versions of Excel is<br />

=IF(ISERR(FIND(“ “,A1)),A1,RIGHT(A1,LEN(A1)-FIND(“ “,A1,1)))<br />

Extracting first names, middle names, and last names<br />

Suppose you have a list consisting of people’s names in a single column. You have to separate these names<br />

into three columns: one for the first name, one for the middle name or initial, and one for the last name.<br />

This task is more complicated than you may think because it must handle the situation for a missing middle<br />

initial. However, you can still do it.<br />

The task becomes a lot more complicated if the list contains names with titles (such as Mr. or<br />

Dr.) or names followed by additional details (such as Jr. or III). In fact, the following formulas<br />

will not handle these complex cases. However, they still give you a significant head start if you’re willing to<br />

do a bit of manual editing to handle special cases.<br />

NOTE<br />

The formulas that follow all assume that the name appears in cell A1.<br />

You can easily construct a formula to return the first name:<br />

=LEFT(A1,FIND(“ “,A1)-1)<br />

This formula returns the last name:<br />

=RIGHT(A1,LEN(A1)-FIND(“*”,SUBSTITUTE(A1,” “,”*”,LEN(A1)-<br />

LEN(SUBSTITUTE(A1,” “,””)))))<br />

The next formula extracts the middle name and requires that you use the other formulas to extract the first<br />

name and the last name. It assumes that the first name is in B1 and the last name is in D1. Here’s what it<br />

looks like:<br />

=IF(LEN(B1&D1)+2>=LEN(A1),””,MID(A1,LEN(B1)+2,LEN(A1)-LEN(B1&D1)-2))<br />

As you can see in Figure 12.5, the formulas work fairly well. There are a few problems, however, notably<br />

names that contain four “words.” But, as I mentioned earlier, you can clean these cases up manually.<br />

219

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

Saved successfully!

Ooh no, something went wrong!