18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Part II<br />

Working with Formulas and Functions<br />

Replacing text with other text<br />

In some situations, you may need to replace a part of a text string with some other text. For example, you<br />

may import data that contains asterisks, and you need to convert the asterisks to some other character. You<br />

could use Excel’s Home ➪ Editing ➪ Find & Select ➪ Replace command to make the replacement. If you<br />

prefer a formula-based solution, you can take advantage of either of two functions:<br />

n<br />

n<br />

SUBSTITUTE replaces specific text in a string. Use this function when you know the character(s)<br />

to be replaced but not the position.<br />

REPLACE replaces text that occurs in a specific location within a string. Use this function when<br />

you know the position of the text to be replaced but not the actual text.<br />

The following formula uses the SUBSTITUTE function to replace 2006 with 2007 in the string 2006<br />

Budget. The formula returns 2007 Budget.<br />

=SUBSTITUTE(“2006 Budget”,”2006”,”2007”)<br />

The following formula uses the SUBSTITUTE function to remove all spaces from a string. In other words, it<br />

replaces all space characters with an empty string. The formula returns 2007OperatingBudget.<br />

=SUBSTITUTE(“2007 Operating Budget”,” “,””)<br />

The following formula uses the REPLACE function to replace one character beginning at position 5 with<br />

nothing. In other words, it removes the fifth character (a hyphen) and returns Part544.<br />

=REPLACE(“Part-544”,5,1,””)<br />

Finding and searching within a string<br />

Excel’s FIND and SEARCH functions enable you to locate the starting position of a particular substring<br />

within a string:<br />

n<br />

n<br />

FIND finds a substring within another text string and returns the starting position of the substring.<br />

You can specify the character position at which to begin searching. Use this function for<br />

case-sensitive text comparisons. Wildcard comparisons are not supported.<br />

SEARCH finds a substring within another text string and returns the starting position of the substring.<br />

You can specify the character position at which to begin searching. Use this function for<br />

non-case-sensitive text or when you need to use wildcard characters.<br />

The following formula uses the FIND function and returns 7, the position of the first m in the string. Notice<br />

that this formula is case-sensitive.<br />

=FIND(“m”,”Big Mama Thornton”,1)<br />

The formula that follows, which uses the SEARCH function, returns 5, the position of the first m (either<br />

uppercase or lowercase):<br />

=SEARCH(“m”,”Big Mama Thornton”,1)<br />

You can use the following wildcard characters within the first argument for the SEARCH function:<br />

TIP<br />

n<br />

n<br />

Question mark (?) matches any single character.<br />

Asterisk (*) matches any sequence of characters.<br />

If you want to find an actual question mark or asterisk character, type a tilde (~) before the<br />

question mark or asterisk.<br />

216

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

Saved successfully!

Ooh no, something went wrong!