There is one option that I always wish Excel should have, and that is counting the 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.
But when it comes to Excel there is no such option to count words. You can count the number of cells which have text but not actual words in them. As you know, in Excel, we have functions and you can use them to calculate almost everything. You can create a formula that can count words from a cell.
Today in this post, you will learn how to count words in Excel from a cell, a range of cells, or even the entire worksheet. And I’ll also show you how to count a specific word from a range of cells.
1. Count Words from a Single Cell
To count words from a cell you need to combine the LEN function with the SUBSTITUTE function. And the formula will be (Text is in cell A1):
=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1
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. Right?
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 to them. To understand this formula you need to split it into three parts.
In the first part, you used the LEN function to count the number of characters from cell A1. And in the second and third parts, you have combined SUBSTITUTE with LEN to remove spaces from the cell and then count the characters. 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 numbers get the number of spaces and in the end, you must add one to it. It returns 7 in the result which is the total number of words in the cell.
Important: When you use the above formula it will return 1 even if the cell is blank so it’s better to wrap it with the IF function to avoid this problem.
=IF(ISBLANK(A2),0,LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1)
This formula will first check the cell and only return the word count if there is a value in the cell.
2. Using a UDF
Apart from the above formulas, I have written a small code to create a UDF for this. This code will help you to create a custom function that will simply return the word count. In short, you don’t need to combine any functions.
Function MyWordCount(rng As Range) As Integer
MyWordCount = UBound(Split(rng.Value, " "), 1) + 1
End Function
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: Formula Bar in Excel
3. 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:
=SUMPRODUCT(LEN(A1:A11)-LEN(SUBSTITUTE(A1:A11," ",""))+1)
In the above formula, A1:A11 is the range of cells and when you enter the formula it returns 77 in the result.
How it Works
This formula works in the same way as the first method works but is just a small advance. The only difference is you have wrapped it in SUMPRODUCT and referred to the entire range instead of a single cell.
Do you know that SUMPRODUCT can take arrays? So, when you use it, it returns an array where you have a count of words for each cell. And in the end, it sums those counts and tells you the count of words in the column.
4. Word Count from the Entire Worksheet
This code is one of the useful macro codes which I use in my work, and it can help you to count all the words from a worksheet.
Sub Word_Count_Worksheet()
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
End If
WordCnt = WordCnt + N
Next rng
MsgBox "There are total " & Format(WordCnt, "#,##0") & " words in the active worksheet"
End Sub
When you run it, it will show a message box with the number of words you have in the active worksheet.
Related: What is VBA in Excel
5. 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 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 occurrences of the word “Monday”.
For this, the formula is:
=SUMPRODUCT((LEN(D6:D9)-LEN(SUBSTITUTE(D6:D9,"Monday","")))/LEN("Monday"))
And when you enter it, it returns to the count of the word “Monday”. That’s 4.
Important: 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.
How it Works
To understand this function, again you need to split it into four parts. In the first part, the LEN function returns an array of the count of characters from the cells.
The second part returns an array of the count of characters from the cells by removing the word “Monday”.
In the third part, the LEN function returns the length of characters of wor word “Monday”.
After that, subtracts part one from part two and then divides 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 gives the count of “Monday” from the range.
Download Sample File
- Ready
Conclusion
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 the 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.
Want to get the word count in Excel? Believe it or not, Excel does not have an inbuilt word counter.
But don’t worry.
A cool bunch of excel functions (or a little bit of VBA if you’re feeling fancy) can easily do this for you.
In this tutorial, I will show a couple of ways to count words in Excel using simple formulas. And at the end, will also cover a technique to create a custom formula using VBA that will quickly give you the word count of any text in any cell.
Formula to Get Word Count in Excel
Before I give you the exact formula, let’s quickly cover the logic to get the word count.
Suppose I have a sentence as shown below for which I want to get the word count.
While Excel cannot count the number of words, it can count the number of spaces in a sentence.
So to get the word count, we can count these spaces instead of words and add 1 to the total (as the number of space would be one less the number of words).
Now there can be two possibilities:
- There is a single space between each word
- There are multiple spaces between words.
So let’s see how to count the total number of words in each case.
Example 1 – When there is a single space between words
Let’s say I have the following text in cell A1: Let the cat out of the bag
To count the number of words, here is the formula I would use:
=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1
This would return ‘7’ as a result.
Here is how this formula works:
- LEN(A1) – This part of the formula returns 26, which is the total number of characters in the text in cell A1. It includes the text characters as well as the space characters.
- SUBSTITUTE(A1,” “,””) – This part of the formula removes all the spaces from the text. So the result, in this case, would be Letthecatoutofthebag.
- LEN(SUBSTITUTE(A1,” “,“”) – This part of the formula counts the total number of characters in the text that has no spaces. So the result of this would be 20.
- LEN(A1)-LEN(SUBSTITUTE(A1,” “,“”)) – This would subtract the text length without spaces from the text length with spaces. In the above example, it would be 26-20 which is 6.
- =LEN(A1)-LEN(SUBSTITUTE(A1,” “,“”))+1 – We add 1 to the overall result as the total number of spaces is one less than the total number of words. For example, there is one space in two words and two spaces in three words.
Now, this works well if you have only one space character between words. But it wouldn’t work if you have more than one space in between words.
In that case, use the formula in the next example.
Example 2: When there are multiple spaces between words
Let’s say you have the following text: Let the cat out of the bag
In this case, there are multiple space characters between words.
To get the word count, we first need to remove all the extra spaces (such that there is only one space character between two words) and then count the total number of spaces.
Here is the formula that will give us the right number of words:
=LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))+1
This is a similar formula used in the above example, with a slight change – we have also used the TRIM function here.
Excel TRIM function removes any leading, trailing, and extra spaces (except single spaces between words).
The rest of the formula works the same (as explained in Example 1).
Note: If there are no spaces between words, it is considered as one word.
Using VBA Custom Function to Count Words in Excel
While the above formulas work great, if you have a need to calculate the word count often, you can use VBA to create a custom function (also called a User Defined Function).
The benefit of using a custom function is that you can create it once and then use it like any other regular Excel function. So instead of creating a long complex formula as we did in the two examples above, you have a simple formula that takes the cell reference and instantly gives you the word count.
Here is the code that will create this custom function to get the word count in Excel.
Function WordCount(CellRef As Range) Dim TextStrng As String Dim Result() As String Result = Split(WorksheetFunction.Trim(CellRef.Text), " ") WordCount = UBound(Result()) + 1 End Function
Once created, you can use the WordCount function just like any other regular Excel function.
In the above code for the custom function, I have used the worksheet TRIM function to remove any leading, trailing, and double spaces in between words. This ensures that all the three cells give the same result, as only the words are counted and not the double spaces.
How this formula works:
The above VBA code first uses the TRIM function to remove all the leading, trailing and double spaces from the text string in the referenced cell.
Once it has the cleaned string, it uses the SPLIT function in VBA to split the text string based on the delimiter, which we have specified to be the space character. So each word is separated as stored as a separate item in the Result variable.
We then use the UBOUND function to count the total number of items that got stored in the Result variables. Since VBA has a base of 0, we need to add 1 to get the total number of words.
This means that Result(0) stores the first word, Result(1) stores the second word, and so on. Since this counting starts from 0, we need to add 1 to get the real word count.
Where to Put this Code?
When creating a custom function, you need to put the code in the VB Editor of the workbook (which is the back end of the workbook where you can write code to automate tasks and create custom functions).
Below are the steps to put the code for the ‘GetNumeric’ function in the workbook.
- Go to the Developer tab.
- Click on Visual Basic option. This will open the VB editor in the backend.
- In the Project Explorer pane in the VB Editor, right-click on any object for the workbook in which you want to insert the code. If you don’t see the Project Explorer go to the View tab and click on Project Explorer.
- Go to Insert and click on Module. This will insert a module object for your workbook.
- Copy and paste the code in the module window.
Once you have copied the code in the code window, you can go back to your worksheet and use this function just like any other regular Excel function.
Just type =Word and it will show you the formula in the list.
It takes one argument, which is the cell reference and instantly gives you the word count in it.
You May Also Like the Following Excel Tutorials:
- How to Count Cells that Contain Text Strings.
- Using Multiple Criteria in Excel COUNTIF and COUNTIFS Function.
- How to Add Leading Zeroes in Excel.
- Remove Spaces in Excel – Leading, Trailing, and Double.
- How to Extract the First Word from a Text String in Excel
Count Words in a Cell of Excel
There is no in-built excel formula to find the Word Count and therefore, it needs to be entered manually. You can make use of the formula below to calculate wordcount in excel –
=LEN(TRIM(cell))-LEN(SUBSTITUTE(cell,” “,””))+1
Let us understand the working of this formula.
To begin with, we utilize the SUBSTITUTE functionSubstitute function in excel is a very useful function which is used to replace or substitute a given text with another text in a given cell, this function is widely used when we send massive emails or messages in a bulk, instead of creating separate text for every user we use substitute function to replace the information.read more to evacuate and displace all spaces in the cell with a vacant content string (“). The LEN functionThe Len function returns the length of a given string. It calculates the number of characters in a given string as input. It is a text function in Excel as well as an inbuilt function that can be accessed by typing =LEN( and entering a string as input.read more restores the length of the string without spaces.
Next, we subtract the string length without spaces from the absolute length of the string. The number of words in a cell is equivalent to the number of spaces plus 1. So, we add 1 to the word count.
Further, we utilize the TRIM functionThe Trim function in Excel does exactly what its name implies: it trims some part of any string. The function of this formula is to remove any space in a given string. It does not remove a single space between two words, but it does remove any other unwanted spaces.read more to remove extra spaces in a cell. A worksheet may contain a lot of imperceptible spaces. Such coincidental occurrence might be towards the start or end of the text (leading and trailing spaces). Since extra spaces return an incorrect word count, the TRIM function is used before computing the length of the string.
The steps to count the total number of words in a cell of Excel are listed as follows:
- Select the cell in the Excel sheet where you want the result to appear.
- For counting the number of words in cell A1, enter the formula shown in the following image.
- Click “Enter” and the exact number of words appear in cell B1.
Table of contents
- Count Words in a Cell of Excel
- How to Count the Total Number of Words in a Range of Cells?
- How to Count Specific Words in a Range?
- Frequently Asked Questions
- Recommended Articles
How to Count the Total Number of Words in a Range of Cells?
To count the number of words in a range of cells, apply the equation that counts the words in a cell and implant it either inside the SUM or the SUMPRODUCT function.
The formula to count words of a particular range is “=LEN(TRIM(cell))-LEN(SUBSTITUTE(cell,” “,””))+1.”
- Step 1: Select the range of data whose words you wish to count.
- Step 2: Enter the formula in the cell where you want the result to display as shown in the succeeding image.
- Step 3: Click “Enter” and the result appears in cell B1.
- Step 4: Drag the fill handle to all cells to get the word count of each cell in Excel.
How to Count Specific Words in a Range?
To count the number of times a specific word appears in a range of cells, we utilize a comparative methodology. We count the explicit words in a cell and consolidate it with the SUM or SUMPRODUCT functionThe SUMPRODUCT excel function multiplies the numbers of two or more arrays and sums up the resulting products.read more.
- Step 1: Select the cell and enter the formula “=(LEN(cell)-LEN(SUBSTITUTE(cell,word,””)))/LEN(word)” as shown in the following image.
- Step 2: Click “Enter” to see the word count in cell A14. The formula we used above helps us know the number of times the word “February” is present in cell A2.
The result in cell A14 is 4.
Frequently Asked Questions
#1 – How to count the number of times a single character appears in a cell?
The formula to count the occurrence of a single character in a cell is stated as follows:
=LEN(cell_ref)-LEN(SUBSTITUTE(cell_ref,”a”,””))
The “cell_ref” stands for cell reference. The letter “a” stands for the character that the user wants to count.
#2 – How to count the number of times a single character appears in a range of cells?
The formula to count the occurrence of a single character in a range of cells is stated as follows:
=SUM(LEN(range)-LEN(SUBSTITUTE(range,”a”2,””)))
The “range” stands for the range of cells to which the formula is applied. The letter “a” stands for the character that the user wants to count.
#3 – How to count the number of times a specific word appears in a row or a column?
The steps to count the number of times a particular word appears in a row or a column are listed as follows:
1- Select the row or the column in which the word is to be counted. The row is selected by clicking the number on the left-hand side. The column is selected by clicking the letter that appears on top of the column.
2 – In the formula tab, click “Define Name” and enter a name for the row or the column in the “New Name” box.
3 – If the column is named “NamesColumn,” the cells in this column will use “NamesColumn” for reference.
4 – Apply the formula “=COUNTIF(NamesColumn,”Jack”)” to count the number of times “Jack” appears in the “NamesColumn.”
Note: Every time a new name is added to a cell of “NamesColumn,” the result of the formula will automatically update.
- The formula to count words of a particular range is “=LEN(TRIM(cell))-LEN(SUBSTITUTE(cell,” “,””))+1.”
- The word count formula is combined with the SUM or SUMPRODUCT function to handle arrays.
- The SUBSTITUTE function replaces all the spaces of the cell with a vacant content string (“).
- The LEN function restores the length of the string without spaces.
- The TRIM function removes the leading and trailing spaces found at the beginning or at the end of the text.
- The number of words in a cell is equivalent to the number of spaces plus 1.
Recommended Articles
This has been a guide to Word Count in Excel. Here we discuss how to count the total number of words in a cell and an excel range along with practical examples and a downloadable template. You may learn more about Excel from the following articles –
- Count Rows in Excel | ExamplesThere are numerous ways to count rows in Excel using the appropriate formula, whether they are data rows, empty rows, or rows containing numerical/text values. Depending on the circumstance, you can use the COUNTA, COUNT, COUNTBLANK, or COUNTIF functions.read more
- Count Colored Cells In ExcelTo count coloured cells in excel, there is no inbuilt function in excel, but there are three different methods to do this task: By using Auto Filter Option, By using VBA Code, By using FIND Method.
read more - Excel Count FormulaThe COUNT function in excel counts the number of cells containing numerical values within the given range. It is a statistical function and returns an integer value. The syntax of the COUNT formula is “=COUNT(value 1, [value 2],…)”
read more - How to Count Unique Values in Excel?In Excel, there are two ways to count values: 1) using the Sum and Countif function, and 2) using the SUMPRODUCT and Countif function.read more
- Compare Two Lists in ExcelThe five different methods used to compare two lists of a column in excel are — Compare Two Lists Using Equal Sign Operator, Match Data by Using Row Difference Technique, Match Row Difference by Using IF Condition, Match Data Even If There is a Row Difference, Partial Matching Technique.read more
no-override
Reader Interactions
Excel does not have its own tool that lets you simply look at the number of words in a document (like Word does). But is it possible to find out anyway?
Yes it is – but it’s a bit convoluted, and it also only works on one cell at a time. Don’t worry, though – we will see at the end how to make it work on a group of cells. Let’s explore how to count words in Excel.
The Excel Functions We’ll Use to Count Characters
We need to learn about three Excel functions, LEN()
, TRIM()
and SUBSTITUTE()
, before we can use them in the formula.
How to Use the LEN()
Function in Excel
The LEN()
function takes a cell with text content and gives back the number of characters in that cell.
For example, if we write The horse under the three
in a cell, and we use the LEN()
function to calculate the number of characters in that sentence in another cell, we’ll get 25
. You can see how it works here:
By specifying that we want the LEN()
of cell B1 (LEN(B1)
, in cell B2 above), Excel does this calculation for us.
Note: I’ll explain why I included the spelling error («three» instead of «tree») below.
How to Use TRIM()
Function in Excel
The TRIM()
function takes a cell with text content and gives back the same text without any white space at the beginning or end.
For example, say we have a cell that looks like this: The horse under the three
(with 7 spaces before the text and 2 at the end. It has a total length of 34 characters, including the spaces.
The TRIM()
function will give us back The horse under the three
(with just the original 25 characters) without the spaces at the beginning or the end. Here’s what it looks like:
You can see that, similar to the example above with LEN()
, when we put the TRIM()
instructions in cell B4, Excel calculates the correct value in cell B5.
How to Use the SUBSTITUTE()
Function in Excel
The SUBSTITUTE()
function will replace a piece of the text with another bit of text. For example, in the text we have been using there is a spelling error (instead of tree
we have three
). We can fix it using the SUBSTITUTE()
function.
The syntax is SUBSTITUTE(text, old_text, new_text, [instance_num])
, with text
being the text we are going to change. In this case, we’ll have the text we want to change, and the old_text
and the part we want to change (three
) which will be replaced with the new_text
(tree
).
The complete formula is SUBSTITUTE(B4, "three", "tree")
. Note that text in a formula always needs to be put in quotes. Here’s how it works:
Just in case you need to know, instance_num
is an optional parameter that you use in case there are multiple instances of old_text
in the text and you want to change only one of them. But we aren’t using it here.
We have learned how to use the above single functions, and now we need to use them together in a somewhat convoluted way.
Before putting them together, let’s try to understand how we are using them, and then we will build together the complete formula.
How Word Count in Excel Works
Excel does not have a proper word count tool or formula, but there is one thing we can count, and that is characters, as we’ve learned above. Specifically, we are going to count the number of spaces inside the string. And from that, we are going to derive the number of words just adding 1 to the number of spaces.
When we look at our example, we can see that the string The horse under the tree
has four spaces. If we add one, we get five, the total number of words in the sentence.
Counting spaces is also not a trivial task. Since there is not a specific tool or formula that can count just spaces, we need to be a bit creative.
What we are going to do is count the number of characters in the string, and then count the number of characters in the string when the spaces have been removed (we can use SUBSTITUTE(text, " ", "")
for this). Then we’ll take the difference between the two.
The horse under the tree
has 24 characters, while Thehorseunderthetree
has 20 characters. The difference is 4, which is the number of spaces in the original string. If we add 1 we get 5, the number of words.
Putting it into Practice
Now we need to put in a single formula that we have seen in the last paragraph. This formula has three components:
- the length of the sentence with spaces at the beginning or at the end of the sentence removed (we want to count only spaces between the words), so we’ll use
LEN(TRIM(text))
- the length of the string without spaces, in this case, we don’t need to use
TRIM()
as we are removing all spaces, soLEN(SUBSTITUTE(text, " ", ""))
- Then we just add
1
.
The complete formula is: LEN(TRIM(text)) - LEN(SUBSTITUTE(text, " ", "")) + 1
.
How to Create a Custom Function to Count Words in Excel
We have learned how to count words in a cell, but maybe we don’t want to type all that every time we need to count the number of words.
Fortunately, we can solve this by creating a custom function to count words. We can also have a custom function to count the total number of words in multiple cells.
How to Create a Custom Function with Visual Basic for Applications
We can open the VBA editor with Alt + F11
(FN + Alt + F11
for Mac). Then we can go to Insert > Module, and we are ready to write our function.
We can use what we have already written as a starting point, but we need to replace SUBSTITUTE
, as that doesn’t exist in Visual Basic, with the REPLACE
function. So now we’ll have LEN(TRIM(text)) - LEN(REPLACE(text, " ", "")) + 1
.
Let’s name the new function we want to create. I have chosen the name WORDCOUNT
, but you can use any name you want. Just replace it in the two places it’s written with the name of your choice.
Function WORDCOUNT(text)
WORDCOUNT = LEN(TRIM(text)) - LEN(REPLACE(text, " ", "")) + 1
End Function
Once you add this code in the editor, you have created the function. Now you can close the editor and enjoy your new function! But keep in mind that it only works for this workbook.
So now let’s make the function work with more than one cell, and then we can also add it permanently to Excel.
How to Build a Custom Excel Function to Count the Total Number of Words in a Group of Cells
We will now update the function to work with a range of cells to make it a bit more useful. We take the same code as above, and apply it to every cell within a range, summing together the number of words in each cell.
Replace the code we wrote before with the following:
Function WORDCOUNT(rng As Range)
Count = 0
For Each cl In rng
thisCount = LEN(TRIM(cl.Value)) - LEN(REPLACE(cl.Value, " ", "")) + 1
Count = Count + thisCount
Next
WORDCOUNT = Count
End Function
Note: this version works with a single range of cells, and all cells selected must contain text. You could try to make your own more versatile version if you want to, just explore VBA on your own!
Lastly, we want to make sure that our function is available in every Excel Work Book. To do that we have to close the VBA editor and save the Book we are working in as *.xlam
, the Excel Add-In file type.
To do that we can go to File > Save As, give the file a name that will let us recognize it, like «WordCount», chose the format «Excel Add-In (*.xlam)» from the drop-down menu. Don’t change the folder in which you save the file, as it is set automatically to an AddIns folder.
Now that we have created the file, we need to import it into Excel. To do that we go to File > Options > Add-ins. At the bottom of the window select «Excel Add-ins» from the dropdown menu, and click Go…. In the new window use the Browse… button, and there it should open the AddIns folder we have saved the file in. Select it and press Ok, then Ok again. Now the WORDCOUNT()
function will be available every time you use Excel.
Conclusion
In this article, we have learned how to count words in a string in Excel.
And even though Excel does not have a readymade tool for counting words, we learned how to create our own custom function to avoid having to write each formula every time we want to get the number of words in a string.
Finally, we also learned how to expand our function so that it works with any number of cells.
Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started
Содержание
- Word count from excel
- Word Count in Excel
- Count Words in a Cell of Excel
- How to Count the Total Number of Words in a Range of Cells?
- How to Count Specific Words in a Range?
- Frequently Asked Questions
- Key Takeaways
- Recommended Articles
- How to count words in Excel
- How to count the total number of words in a cell
- How this word counting formula works
- Improved formula that properly handles empty cells
- How to count specific words in a cell
- How this formula counts the occurrences of a specific text in a cell
- Case-sensitive formula to count specific words in a cell
- Case-insensitive formula to count specific words in a cell
- Count the total number of words in a range
- Count specific words in a range
Word count from excel
Use Scrybs automated word counter
The first and most simple way is to use Scrybs’ word counter for free! Scrybs, as an online translation service needs to count the number words in documents submitted by our clients. This includes excel spreadsheets. Merely upload your spreadsheet and the word count will display in the bottom right.
Counting words by using embedded excel functions
There are two formulas that would assist you in finding the number of words in your spreadsheet:
A.) If you need to count the words inside a specific cell you can use specific excel functions. For example, if you need to count the number of words in cell A1, enter the below formula into cell B1 and then hit ENTER. If done correctly, it would count the number of words in cell A1.
=IF(LEN(TRIM(A1))=0,0,LEN(TRIM(A1))-LEN(SUBSTITUTE(A1,» «,»»))+1)
B.) If you have several cells within which you need a word-count for, the formula would be slightly altered. For example, if you wish to count the number of words in xls within cells A1:C7 you will be copying the below formula into cell D1. Once, done select Shift + Ctrl + Enter and the number of words in your selected cells will be displayed.
=SUM(IF(LEN(TRIM(A1:C7))=0,0,LEN(TRIM(A1:C7))-LEN(SUBSTITUTE(A1:C7,» «,»»))+1))
Using predefined functions
Another option to count words in Excel is by a predefined function. To do so, please follow the following instructions:
- Click on Developer, then go to Visual Basic and choose a new Microsoft Visual Basic for applications.
- Once the window is opened click on Insert, choose Module and input the following:
Function intWordCount(rng As Range) As Integer
intWordCount = UBound(Split(rng.Value, » «), 1) + 1
End Function - Now that you have defined the function, you can use it in an excel spreadsheet.
- For example, if you want to know the number of words you have in cell A1 you will need to enter the following formula into cell B1:
=intwordcount(A1) - Hit the Enter key and you will have your word count!
It is important to note, however, that this method can only be used to count the number of words in a cell and not the number of words in a spreadsheet.
Using user defined functions in VBA
You can also count words in Excel by writing up user defined functions with VBA code.
Start by selecting the cell, or the range of cells you’d like to know the word count for. Once selected click on Developer, then go to Visual Basic and choose a new “Microsoft Visual Basic for Applications”. Once a window is opened click on Insert, choose Module and input the following:
Sub CountWords()
Dim WordCount 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
End If
WordCount = WordCount + N
Next Rng
MsgBox «Words In ActiveSheet Sheet: » & Format(WordCount,»#,##0″)
End Sub
Hit the Play button to bring the code to life, and the number of words in the selected portion will be shown in a pop-up box.
Lastly, you can also use Kutools to count words in Excel:
You can install Kuttols for Excel and use this tool to count words in a cell or in a range of cells, easily with just few clicks.
Start by selecting the cell you want the result to be displayed in, then click on “Kutools”, go to “Formulas”, and click on “Count words in range”.
Inside the formula helper dialog box you’ll need to enter the cell or cells you wish to have the word count for. Then you would click on “OK”. This will result in the word count being displayed in your previously selected cell.
Источник
Word Count in Excel
Count Words in a Cell of Excel
There is no in-built excel formula to find the Word Count and therefore, it needs to be entered manually. You can make use of the formula below to calculate wordcount in excel –
=LEN(TRIM(cell))-LEN(SUBSTITUTE(cell,” “,””))+1
Let us understand the working of this formula.
Next, we subtract the string length without spaces from the absolute length of the string. The number of words in a cell is equivalent to the number of spaces plus 1. So, we add 1 to the word count.
Further, we utilize the TRIM function TRIM Function The Trim function in Excel does exactly what its name implies: it trims some part of any string. The function of this formula is to remove any space in a given string. It does not remove a single space between two words, but it does remove any other unwanted spaces. read more to remove extra spaces in a cell. A worksheet may contain a lot of imperceptible spaces. Such coincidental occurrence might be towards the start or end of the text (leading and trailing spaces). Since extra spaces return an incorrect word count, the TRIM function is used before computing the length of the string.
The steps to count the total number of words in a cell of Excel are listed as follows:
- Select the cell in the Excel sheet where you want the result to appear.
For counting the number of words in cell A1, enter the formula shown in the following image.
Click “Enter” and the exact number of words appear in cell B1.
Table of contents
How to Count the Total Number of Words in a Range of Cells?
To count the number of words in a range of cells, apply the equation that counts the words in a cell and implant it either inside the SUM or the SUMPRODUCT function.
The formula to count words of a particular range is “=LEN(TRIM(cell))-LEN(SUBSTITUTE(cell,” “,””))+1.”
- Step 1: Select the range of data whose words you wish to count.
- Step 2: Enter the formula in the cell where you want the result to display as shown in the succeeding image.
- Step 3: Click “Enter” and the result appears in cell B1.
- Step 4: Drag the fill handle to all cells to get the word count of each cell in Excel.
How to Count Specific Words in a Range?
To count the number of times a specific word appears in a range of cells, we utilize a comparative methodology. We count the explicit words in a cell and consolidate it with the SUM or SUMPRODUCT function SUMPRODUCT Function The SUMPRODUCT excel function multiplies the numbers of two or more arrays and sums up the resulting products. read more .
- Step 1: Select the cell and enter the formula “=(LEN(cell)-LEN(SUBSTITUTE(cell,word,””)))/LEN(word)” as shown in the following image.
- Step 2: Click “Enter” to see the word count in cell A14. The formula we used above helps us know the number of times the word “February” is present in cell A2.
The result in cell A14 is 4.
Frequently Asked Questions
The formula to count the occurrence of a single character in a cell is stated as follows:
=LEN(cell_ref)-LEN(SUBSTITUTE(cell_ref,”a”,””))
The “cell_ref” stands for cell reference. The letter “a” stands for the character that the user wants to count.
The formula to count the occurrence of a single character in a range of cells is stated as follows:
The “range” stands for the range of cells to which the formula is applied. The letter “a” stands for the character that the user wants to count.
The steps to count the number of times a particular word appears in a row or a column are listed as follows:
1- Select the row or the column in which the word is to be counted. The row is selected by clicking the number on the left-hand side. The column is selected by clicking the letter that appears on top of the column.
2 – In the formula tab, click “Define Name” and enter a name for the row or the column in the “New Name” box.
3 – If the column is named “NamesColumn,” the cells in this column will use “NamesColumn” for reference.
4 – Apply the formula “=COUNTIF(NamesColumn,”Jack”)” to count the number of times “Jack” appears in the “NamesColumn.”
Note: Every time a new name is added to a cell of “NamesColumn,” the result of the formula will automatically update.
Key Takeaways
- The formula to count words of a particular range is “=LEN(TRIM(cell))-LEN(SUBSTITUTE(cell,” “,””))+1.”
- The word count formula is combined with the SUM or SUMPRODUCT function to handle arrays.
- The SUBSTITUTE function replaces all the spaces of the cell with a vacant content string (“).
- The LEN function restores the length of the string without spaces.
- The TRIM function removes the leading and trailing spaces found at the beginning or at the end of the text.
- The number of words in a cell is equivalent to the number of spaces plus 1.
Recommended Articles
This has been a guide to Word Count in Excel. Here we discuss how to count the total number of words in a cell and an excel range along with practical examples and a downloadable template. You may learn more about Excel from the following articles –
Источник
How to count words in Excel
by Svetlana Cheusheva, updated on February 7, 2023
The tutorial explains how to count words in Excel by using the LEN function in combination with other Excel functions, and provides case-sensitive and case-insensitive formulas to count total or specific words/text in a cell or range.
Microsoft Excel has a handful of useful functions that can count nearly everything: the COUNT function to count cells with numbers, COUNTA to count non-blank cells, COUNTIF and COUNTIFS to conditionally count cells, and LEN to calculate the length of a text string.
Unfortunately, Excel doesn’t provide any built-in tool for counting the number of words. Luckily, by combining serval functions you can make more complex formulas to accomplish almost any task. And we will be using this approach to count words in Excel.
How to count the total number of words in a cell
To count words in a cell, use the following combination of LEN, SUBSTITUTE and TRIM functions:
Where cell is the address of the cell where you want to count words.
For example, to count words in cell A2, use this formula:
And then, you can copy the formula down to count words in other cells of column A:
How this word counting formula works
First, you use the SUBSTITUTE function to remove all spaces in the cell by replacing them with an empty text string («») for the LEN function to return the length of the string without spaces:
After that, you subtract the string length without spaces from the total length of the string, and add 1 to the final word count, since the number of words in a cell equals to the number of spaces plus 1.
Additionally, you use the TRIM function to eliminate extra spaces in the cell, if any. Sometimes a worksheet may contain a lot of invisible spaces, for example two or more spaces between words, or space characters accidentally typed at the beginning or end of the text (i.e. leading and trailing spaces). And all those extra spaces can throw your word count off. To guard against this, before calculating the total length of the string, we use the TRIM function to remove all excess spaces except for single spaces between words.
Improved formula that properly handles empty cells
The above formula to count words in Excel could be called perfect if not for one drawback — it returns 1 for empty cells. To fix this, you can add an IF statement to check for blank cells:
=IF(A2=»», 0, LEN(TRIM(A2))-LEN(SUBSTITUTE(A2,» «,»»))+1)
As you can see in the screenshot above, the formula returns zero for blank cells, and the correct word count for non-empty cells.
How to count specific words in a cell
To count how many times a certain word, text, or substring appears in a cell, use the following formula:
For example, let’s calculate the number of «moon» occurrences in cell A2:
=(LEN(A2)-LEN(SUBSTITUTE(A2, «moon»,»»)))/LEN(«moon»)
Instead of entering the word to be counted directly in the formula, you can type it in some cell, and reference that cell in your formula. As a result, you will get a more versatile formula to count words in Excel.
Tip. If you plan on copying your formula to multiple cells, be sure to fix the reference to the cell containing the word to count with the $ sign. For example:
=(LEN(A2)-LEN(SUBSTITUTE(A2, $B$1,»»)))/LEN($B$1)
How this formula counts the occurrences of a specific text in a cell
- The SUBSTITUTE function removes the specified word from the original text.
In this example, we remove the word input in cell B1 from the original text located in A2:
SUBSTITUTE(A2, $B$1,»») - Then, the LEN function calculates the length of the text string without the specified word.
In this example, LEN(SUBSTITUTE(A2, $B$1,»»)) returns the length of the text in cell A2 after removing all characters contained in all occurrences of the word «moon«. - After that, the above number is subtracted from the total length of the original text string:
(LEN(A2)-LEN(SUBSTITUTE(A2, $B$1,»»)))
The result of this operation is the number of characters contained in all occurrences of the target word, which is 12 in this example (3 occurrences of the word «moon«, 4 characters each).
Apart from counting the number of certain words in a cell, you can use this formula to count the occurrences of any text (substring). For example, you can count how many times the text «pick» appears in cell A2:
Case-sensitive formula to count specific words in a cell
As you probably know, Excel SUBSTITUTE is a case-sensitive function, and therefore the word counting formula based on SUBSTITUTE is case-sensitive by default:
Case-insensitive formula to count specific words in a cell
If you need to count both uppercase and lowercase occurrences of a given word, use either the UPPER or LOWER function inside SUBSTITUTE to convert the original text and the text you want to count to the same case.
For example, to count the number of occurrences of the word in B1 within cell A2 ignoring case, use this formula:
As demonstrated in the below screenshot, the formula returns the same word count regardless of whether the word is typed in UPPERCASE (cell B1), lowercase (cell D1) or Sentence case (cell C1):
Count the total number of words in a range
To find out how many words a certain range contains, take the formula that counts total words in a cell and embed it within either SUMPRODUCT or SUM function:
SUMPRODUCT is one of few Excel functions that can handle arrays, and you complete the formula in the usual way by pressing the Enter key.
For the SUM function to calculate arrays, it should be used in an array formula, which is completed by pressing Ctrl+Shift+Enter instead of the usual Enter stroke.
For example, to count all words in range A2:A4, use one of the following formulas:
=SUM(LEN(TRIM(A2:A4))-LEN(SUBSTITUTE(A2:A4,» «,»»))+1)
Count specific words in a range
If you want to count how many times a particular word or text appears within a range of cells, use a similar approach — take the formula to count specific words in a cell, and combine it with the SUM or SUMPRODUCT function:
Please remember to press Ctrl+Shift+Enter to correctly complete the array SUM formula.
For example, to count all occurrences of the word entered in cell C1 within the range A2:A4, use this formula:
=SUMPRODUCT((LEN(A2:A4)-LEN(SUBSTITUTE(A2:A4, C1,»»)))/LEN(C1))
As you remember, SUBSTITUTE is a case-sensitive function, and therefore the above formula distinguishes between uppercase and lowercase text:
To make the formula case-insensitive, use either the UPPER or LOWER function:
=SUMPRODUCT((LEN(A2:A4)-LEN(SUBSTITUTE((LOWER(A2:A4)),LOWER(C1),»»)))/LEN(C1))
This is how you count words in Excel. To better understand and probably reverse-engineer the formulas, you are welcome to download the sample Excel Count Words workbook.
If none of the formulas discussed in this tutorial has solved your task, please check out the following list of resources that demonstrate other solutions to count cells, text and individual characters in Excel.
Источник