P. 1
Excel formula to count words

# Excel formula to count words

|Views: 70|Likes:
Excel formula to count words
Excel formula to count words

See more
See less

08/14/2013

pdf

text

original

# Count Words in an Excel Cell

Page 1 of 3

Just added PDF screen steps to Excel Decision Matrix tutorial. Scroll to resource section to find it. Main Menu • Home • 5 Minute Tips ◦ General ◦ Chunkers ◦ Annoyances • Cell Phones • Email • News • Reviews • Term to Learn • Useful Utilities • Web Sites • Excel Tutorials • RSS Help Page Home 5 Minute Tips General Finding Excel Word Count

Finding Excel Word Count
Recently, I attended an industry summit that had an expert’s panel where people provided their best tips. One Excel tip involved filtering cells with a certain number of words. A nice tip, but it left some attendees wondering where Excel’s word count function was. The program doesn’t have this feature, but you can get the answer by creating an Excel formula to count words. (Includes sample Excel worksheet and formula) The summit tip was for a specific product, but opportunities exist where you might want to count words in an Excel cell. I do a similar process when I pull a list of site search queries from my web analytics to see people’s interests. I look at all the cells, but I filter one word entries. The reason is it’s hard for me to guess the searcher’s intent based on one word.

Select Language ▲

Dashboard

http://www.timeatlas.com/5_Minute_Tips/General/Finding_Excel_Word_Count

6/25/2012

Count Words in an Excel Cell

Page 2 of 3

Setting the Stage to is blocked due toWords Counting a security Your page

Send

policy that prohibits access to Category The key to counting Usenet in Excel is to correctly identify the spaces between words. You need to words News remove leading and trailing spaces in the cells or the count will be inflated. There are a couple of ways to do this. A simple way is to use a free Excel add-on I’ve reviewed called ASAP Utilities. Another way is to use the Excel TRIM function. The trim function removes leading and trailing spaces in a cell. This text function also removes extra spaces between words to just one space. In the table below, you can see that the spaces aren’t always obvious.

Before

Scenario

After Trim Function

Example text

Example text

Example text

Double space

Example text

Example text

Trailing space

Example text

In addition to TRIM, I’ll also use Excel’s LEN and SUBSTITUTE functions. These are also considered TEXT functions. LEN returns the number of characters in a string. In my case, the number will reflect the number for each cell. Since a space is considered a character, it is counted. SUBSTITUTE is similar to “search and replace” on a cell except we can specify how many times the substitution should occur. For example, you could indicate once, all, or a specific number. As example, the formula =SUBSTITUTE(A1,"example","sample"), would replace the word “example” with “sample” for cell A1. For our purposes, we want to substitute a space “ “ with nothing. Effectively, the function removes all spaces so the words run together. “Example text” would change to “Exampletext”.

Understanding the Word Count Formula
One nice feature about Excel is that you can nest formulas that include multiple functions. As example, I’ll use LEN, TRIM and substitute in this formula. To get the word count in cell A2 in my spreadsheet, I would use this formula in B2, =IF(LEN(TRIM(A2))=0,0,LEN(TRIM(A2))-LEN(SUBSTITUTE(A2," ",""))+1) While stringing Excel functions together is efficient, it may make the formula intimidating. Let me break it down for you.
Select Language ▲
Dashboard

http://www.timeatlas.com/5_Minute_Tips/General/Finding_Excel_Word_Count

6/25/2012

Count Words in an Excel Cell

Page 3 of 3

1. We TRIM any extra spaces in cell A2 and determine if the cell is blank by using =IF(LEN(TRIM (A2))=0,0. If the cell is blank, it assigns the word count as 0. 2. If A2 isn’t blank, we count the characters in the cell using LEN(TRIM(A2)). You might think of this as our starting character count inclusive of spaces. The superfluous spaces have been removed. 3. We use -LEN(SUBSTITUTE(A2)," ","")) to remove the remaining spaces. We then count the characters in this new string. 4. We take the LEN count from Step 2 and subtract the LEN count from Step 3. We then add one to count to adjust for the first word. If you prefer word problems, think of it this way. If the cell is empty, make the word count = 0. Otherwise, remove the extra spaces and count the characters in the cell. Hold that value as “A”. Now, remove all spaces in that cell and count the characters again. Hold that value as “B”. Your word count is (A-B) + 1. “Sample example text” = LEN count of 19. This is your “A”. “Sampleexampletext” = LEN count of 17. This is your “B”. (19-17)+1 = word count of 3. After writing this formula, I think I have a new appreciation with the ease at which some programs, like Microsoft Word, can return a word count. If you want to see an example with these formulas, you can download the sample Excel spreadsheet.

Related Excel Tutorials
• Excel Sample Worksheet with Word Count Formula • How to use Excel Auto Filter Last Updated (Friday, 18 June 2010 18:36) Instant Site Search
Search