There is one option which I always wish Excel should have and that's count number of words from a cell.
If you work in MS Word there is an inbuilt option on the status bar which shows you how many words are there in the sheet.
Four Different ways to Count Words in Excel
Now without any ado, let's get started.
1. The Formula to Count Words from a Cell
To count words from a cell you need to combine LEN function with SUBSTITUTE function. And the formula will be (Text is in cell A1):
When you refer to a cell using this formula, it will return 7 in the result. And yes, you have a total of 7 words in the cell.
how it works
Before getting into this formula just think this way. In a normal sentence if you have eight words then you will definitely have 7 spaces in those words.
That means you will always have one word more than the spaces. The idea is simple: If you want to count the words, count the spaces and add one in it. Now, to understand this formula you need to split it into three parts.
At this point, you have an equation like this.
The total number of characters with spaces and the total number of characters without spaces.
And when you subtract both of these numbers gets the number of spaces and in the end, you have to add one in it. It returns 7 in the result which is the total number of words in the cell.
When you use the above formula it will return 1 even if the cell is blank so it’s better to wrap it with IF function to avoid this problem.
This formula will first check the cell and only return word count if there is a value in the cell.
Using a UDF
In short, you don’t need to combine any functions.
Function MyWordCount(rng As Range) As Integer
MyWordCount = UBound(Split(rng.Value, " "), 1) + 1
Let me tell you how to use it.
- First of all, enter this code in VBA editor.
- And then come back to your worksheet, and enter “=MyWordCount(” and refer to the cell in which you have value.
And, it will return the word count.
Related Tip: Formula Bar in Excel
2. Count Words from a Range of Cells
Now let’s come to the next level.
And here you need to count words from a range of cells instead of a single cell.
The good news is you just need to use the same formula (just a simple change) which you have used above.
And the formula will be:
In the above formula, A1:A11 is the range of cells and when you enter the formula it returns 77 in the result.
here's how it works
This formula works in the same way as the first method works but just a small advanced. The only difference is you have wrapped it in SUMPRODUCT and refer to the entire range instead of a single cell.
And in the end, it sums those counts and tells you the count of words in the column.
3. Word Count from Entire Worksheet with VBA Code
Dim WordCnt As Long
Dim rng As Range
Dim S As String
Dim N As Long
For Each rng In ActiveSheet.UsedRange.Cells
S = Application.WorksheetFunction.Trim(rng.Text)
N = 0
If S <> vbNullString Then
N = Len(S) - Len(Replace(S, " ", "")) + 1
WordCnt = WordCnt + N
MsgBox "There are total " & Format(WordCnt, "#,##0") & " words in the active worksheet"
4. Count a Specific Word/Text String from a Range
Here you have a different situation.
Let’s say you need to count a specific word from a range of cells or to check the number of times a value appears in a column.
Take this example.
Below you have a range of four cells and from this range, you need to count the count of occurrence of the word “Monday”. For this, the formula is:
And when you enter it, it returns the count of word “Monday”.
It returns the count of the word (word’s frequency) from the range not the count of the cells which have that word.
Monday is there four times in three cells.
...let me explain how it works
To understand this function, again you need to split it into four parts.
In the first part, LEN function returns an array of the count of characters from the cells.
The second part returns an array of the count of character from the cells by removing the word “Monday”.
In the third part, LEN function returns the length of characters of wor word “Monday”.
After that, subtracts part one from part two and then divide it with part three...
...it returns an array with the count of the word “Monday” from each cell.
In the fourth part, SUMPRODUCT returns the sum of this array and give the count of “Monday” from the range.
Whenever you are typing some text in a cell or a range of cells you can these methods to keep a check on the word count.
I wish someday in future Excel will get this option to count words. But, for the time being, you have all these awesome methods.
Which method do you like the most?
Make sure to share your views with me in the comment section, I'd love to hear from you. And please, don’t forget to share this post with your friends, I am sure they will appreciate it.
You must read this next
- Counting Cells with Text: Let’s explore each and every method and learn when we can use them and how they work…
- How to Count Unique Values in Excel: In Excel, you can use different methods to get a count of unique values...
- Random Letter Generator in Excel: We have functions like RAND and RANBETWEEN to generate random numbers but...
- Convert Negative Number to Positive: But have you ever checked how my different methods you have to do this? Well...
- Change to Sentence Case: Well, in sentence case, for an entire sentence, the first letter of the first word should...
- How to Hide Formulas in Excel: Hiding a formula is a simple way to do this so that others can’t able to see which...
- RANKIF in Excel: I’m in love with this function from the last couple of years and today, in this post I will...
- Remove First N Characters in Excel: Even I have created a small UDF to make it super easy for him to remove...
About the Author
Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can ﬁnd him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.