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 5: Manipulating Text 135<br />

For example, assume cell A1 contains the text Annual Profit Figures. The following formula<br />

searches for the word Profit and replaces those six characters with the word Loss:<br />

=REPLACE(A1,SEARCH(“Profit”,A1),6,”Loss”)<br />

This next formula uses the SUBSTITUTE function to accomplish the same effect in a more efficient<br />

manner:<br />

=SUBSTITUTE(A1,”Profit”,”Loss”)<br />

Advanced Text <strong>Formula</strong>s<br />

The examples in this section are more complex than the examples in the previous section. But, as<br />

you’ll see, these formulas can perform some very useful text manipulations.<br />

You can access all the examples in this section on the companion CD-ROM in the text<br />

formula examples.xlsx file.<br />

Counting specific characters in a cell<br />

This formula counts the number of Bs (uppercase only) in the string in cell A1:<br />

=LEN(A1)-LEN(SUBSTITUTE(A1,”B”,””))<br />

This formula uses the SUBSTITUTE function to create a new string (in memory) that has all the Bs<br />

removed. Then the length of this string is subtracted from the length of the original string. The<br />

result reveals the number of Bs in the original string.<br />

The following formula is a bit more versatile. It counts the number of Bs (both upper- and lowercase)<br />

in the string in cell A1.<br />

=LEN(A1)-LEN(SUBSTITUTE(SUBSTITUTE(A1,”B”,””),”b”,””))<br />

Counting the occurrences of a substring in a cell<br />

The formulas in the preceding section count the number of occurrences of a particular character<br />

in a string. The following formula works with more than one character. It returns the number of

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

Saved successfully!

Ooh no, something went wrong!