
That name is one I’m apt to remember, but you can choose a different name for your custom function. In my example, I called the function CellWordCount.
WORD COUNTER EXCEL CODE
You can use the code snippet below and add it as a module in the VB editor. This would save me from repeating these steps each time I needed to do an analysis. Consider a Custom FunctionĪfter using this word count formula several times, I thought it would make more sense to create a custom function and assign it to the Excel workbook. This is your “B.”Īfter writing this formula, I think I have a new appreciation for the ease at which some programs, like Microsoft Word, can return a word count. Hold that value as “B.” Your word count is (A-B) + 1. Hold that value as “A.” Now, remove all spaces in that cell and count the characters again. Otherwise, remove the extra spaces and count the characters in the cell. If the cell is empty, make the word count = 0. If you prefer word problems, think of it this way. Pin Final Word Counts in Column F Presenting Another Way In the screen snap below, my formula is in Column F. This often helps when learning a nested formula. However, you can also add more columns to show various stages. In the above example, I placed the formula in Column B. We then add 1 to the count to adjust for the first word.

The formula below references LEN, TRIM, and SUBSTITUTE. One nice feature of Excel is that you can nest formulas that include multiple functions. All the single spaces have been removed resulting in a string without spaces. “Example text” would change to “Exampletext”. Effectively, the function removes all spaces, so the words run together. For example, you could indicate once, all, or a specific number.įor example, the formula =SUBSTITUTE(A1,”firefox”,”google”) would replace the word “firefox” with “google” for cell reference A1.įor our purposes, we want to substitute a space “ “ with nothing “”. SUBSTITUTE function is similar to “search and replace” on a cell, except we can specify how many times the substitution should occur. Since a “space” is considered a character, it is counted. In my case, the number will reflect the number for each reference cell. LEN function returns the number of characters in a string. These are also considered TEXT functions. In addition to the TRIM function, I’ll also use Excel’s LEN function and SUBSTITUTE functions. You have to compare the counts in Columns B and C Pin Excel sheet with leading and trailing spaces In the screen snap below, you can see that the spaces aren’t always obvious. The trim function removes leading and trailing spaces in a cell.

A simple way is to use an Excel add-on such as ASAP Utilities.Īnother way is to use the Excel TRIM function.

You need to remove leading and trailing spaces in the cells, or the word count will be inflated.

The key to counting words in Excel is to correctly identify and count the spaces between and around the words. For example, I do a similar process when I pull a list of site search queries from my web analytics to see people’s interests. The summit tip was for a specific product, but opportunities exist where you might want to count words in an Excel cell.
