Can you count words in excel

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.

there is an option in word to count words but not in excel

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.

  1. First of all, enter this code in VBA editor.
    add-udf-code-to-vbe-to-count-words-in-excel-cell
  2. 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.

Word Count in Excel - formula

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:

  1. There is a single space between each word
  2. 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

Word Count in Excel - formula

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.

Get Word Count in Excel - Example 1

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

Word Count in Excel - multiple spaces

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).

Get Word Count in Excel - Example 2

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.

Custom Function Created with VBA to get the word count in Excel

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.

  1. Go to the Developer tab.Word Count in Excel - Ribbon for Developer Tab
  2. Click on Visual Basic option. This will open the VB editor in the backend.Click on Visual Basic button in the Excel ribbon
  3. 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.
  4. Go to Insert and click on Module. This will insert a module object for your workbook.Saving a Custom Function code in the module
  5. 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.

VBA Custom Formula shows up in Worksheet

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

Word Count in Excel – How to Check the Number of Words

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:

len

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:

trim

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:

substitute

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.

count-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, so LEN(SUBSTITUTE(text, " ", ""))
  • Then we just add 1.

The complete formula is: LEN(TRIM(text)) - LEN(SUBSTITUTE(text, " ", "")) + 1.

single-formula

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

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:

  1. Select the cell in the Excel sheet where you want the result to appear.

    Word-Count-Example-1

  2. For counting the number of words in cell A1, enter the formula shown in the following image.

    Word-Count-Example-1-1-1

  3. Click “Enter” and the exact number of words appear in cell B1.

    Word-Count-Example-1-2

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.

Word Count Example 2

  • Step 2: Enter the formula in the cell where you want the result to display as shown in the succeeding image.

Word Count Example 2-1

  • Step 3: Click “Enter” and the result appears in cell B1.

Example 2-2

  • Step 4: Drag the fill handle to all cells to get the word count of each cell in Excel.

Example 2-3

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.

Example 4

  • 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.

Example 4-1

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

Do you need to count the words inside a cell or range of cells in your Excel workbook?

You might need to count the number of words in your text data for many reasons. Perhaps you have comma-separated lists and need to count the number of items in each list.

Unfortunately, Excel doesn’t have a built-in method for counting words. But there are a few clever ways to get the result you need.

This post will show you how you can count how many words are in your text data in Excel.

Count Words with the LEN and SUBSTITUTE Functions

This first method will use a combination of the LEN and SUBSTITUTE functions to determine the number of space characters in the text string.

Each word is separated by a space, so knowing the number of spaces will also get you the number of words by adding 1.

= LEN ( B3 ) - LEN ( SUBSTITUTE ( B3, " ", "" ) ) + 1

The above formula will return the count of words in cell B3.

SUBSTITUTE(B3," ","") will take the text in cell B3 and replace all the space characters with an empty character. This removes all the spaces from the text.

The LEN function will return the total number of characters in a text string. You can then use this to get the number of characters in the original text LEN(B3) and the number of characters in the text when spaces are removed LEN(SUBSTITUTE(B3," ","")).

When you take the difference between these, you get the total number of spaces in the text. Then when you add 1, this is the total number of words.

⚠️ Warning: Your text might not always have only one space between each word. If this is the case then the method above won’t get you the word count.

You can first use the TRIM function to ensure your text doesn’t have excess spaces. It will also remove any leading or trailing spaces in the text.

This will guarantee the word count based on space count is accurate.

= LEN ( TRIM ( B3 ) ) - LEN ( SUBSTITUTE ( TRIM ( B3 ), " ", "" ) ) + 1

The above formula will first remove any excess spaces from the text and then return the word count based on the spaces between words.

Count Words with the TEXTSPLIT and COUNTA Functions

Another formula approach to counting the words in your text is to split the text into separate cells first and then count the number of cells this results in.

You can do this with a dynamic array function called TEXTSPLIT. This allows you to split text based on any delimiting character.

You can use this function to split your text based on the space characters. Then you can use the COUNTA function to count the number of split values which are the individual words.

This means you don’t actually need to split the text into the workbook. They are only split during the formula calculation in memory.

= COUNTA ( TEXTSPLIT ( B3, " ",, TRUE ) )

The above formula will return the word count from the text in cell B3.

The TEXTSPLIT(B3," ",,TRUE) part will split the text based on the space character.

Here the TRUE argument skips any blank values that are created during the split due to any excess spaces your text might have. This will help you get an accurate word count based on the spaces.

Now you can use the COUNTA function to count the split results. This gives the word count.

Count Words with Power Query

Power Query is another possible way to get a word count.

This might be ideal if you are already importing your data from external sources or performing other data transformations.

  1. Select your table of data.
  2. Go to the Data tab.
  3. Select the From Table/Range option.

This will open the power query editor and you can add a word count here.

  1. Go to the Add Column tab in the editor.
  2. Select the Custom Column option.

This opens the Custom Column formula editor.

  1. Give the new column a name.
List.Count(Text.PositionOf([Text]," ",Occurrence.All))+1
  1. Enter the above formula into the Custom column formula input area where [Text] is the column of text to count the word in.
  2. Press the OK button.

This will create a new column with the word count results.

The Text.PositionOf function will create a list of the position of each space character in the text. The List.Count function then counts this list to get the total number of spaces to which you then add 1 to get a word count.

Now you can load this back to Excel. Go to the Home tab of the editor and click on the Close and Load command. Then Choose the Table option from the Import Data menu and press the OK button.

This loads the data and new word count column to a new table in your chosen location.

Count Words with VBA

There is no Excel function built for counting words, but you can build your own custom function for this purpose by using VBA.

Then you’ll be able to get the word count with a simple reference to the custom function.

Go to the Developer tab and click on the Visual Basic option found in the Code section of the ribbon. Alternatively, you can press Alt + F11 on your keyboard to open the visual basic editor.

Function WORDCOUNT(rng As Range)

Dim arrText() As String
Dim tempCount As Long
tempCount = 0

For Each c In rng
    arrText = Split(c.Value, " ")
    tempCount = tempCount + (UBound(arrText) + 1)
Next c
WORDCOUNT = tempCount

End Function

Go to the Insert tab of the visual basic editor and select the Module option to add a new module. Then place the above code in the module.

The code creates a function named WORDCOUNT which can be used like any other function in your Excel workbook.

The WORDCOUNT function takes a range reference and then will add up the word count for all the cells in the range.

It does this by looping through each cell and splitting the text into an array based on the space characters. The number of items in the array plus 1 is then the word count for that cell.

This code adds this for each cell to create a running total of the word count as it loops through the range.

= WORDCOUNT ( B3:B7 )

The above formula can now be used in the worksheet to count the number of words in the range B3:B7.

Count Words with Office Scripts

You can also use Office Scripts to get a word count.

You’ll be able to select a range and then run the script which returns the count based on the entire range.

Go to the Automate tab and select the New Script option.

function main(workbook: ExcelScript.Workbook) {

    //getselected range
    let rng = workbook.getSelectedRange();
    let rows = rng.getRowCount();
    let cols = rng.getColumnCount();

    var wordCount = 0;

    //loop through selected cells
    for (let i = 0; i < rows; i++) {
        for (let j = 0; j < cols; j++) {
            //count words and add to running total
            let currCell = rng.getCell(i, j).getValue().toString().trim();
            wordCount = wordCount + currCell.split(" ").length;
        };
    };
    console.log(wordCount)
};

This opens up the Code Editor and you can paste the above code and press the Save script button.

The code will loop through each cell in the selected range and split the text based on the space character. It then counts the number of split items and adds this to the running total.

Press the Run button and the code will count the words in the selected range and write the result in the code editor log.

Count Words with Microsoft Word

This method will allow you to count the words in any selected range, but it does require using Microsoft Word as well.

You can copy the range of values from Excel and then paste them into a new document in Word. You will then be able to use the word-counting feature in Word.

This might not be the most elegant solution, but it will get the job done quickly for those one-time use cases.

  1. Copy the range from Excel.
  2. Open a new document in Microsoft Word and paste the range from Excel.
  3. Go to the Review tab in Word.
  4. Click on the Word Count command in the Proofing section.

This will show you a popup with various statistics including the word count from the document.

Conclusions

Excel doesn’t come with a word count feature, but you can still get the same result with a few other methods.

Formulas combining the LEN and SUBSTITUTE functions or the COUNTA and TEXTSPLIT functions will get you the required count.

Alternatively, you can build your own custom function with VBA that you can use anywhere in the workbook. This will help to simplify the input.

Other advanced options such as counting with Power Query or Office Scripts are also possible.

You can even use another app to do the work by copying and pasting for one-off word counts.

Do you have any extra tips to count words? Let me know in the comments!

About the Author

John MacDougall

John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.

Excel doesn’t have a dedicated function for counting words in a cell. However, with a little ingenuity, you can create such a formula using the SUBSTITUTE and LEN functions, with help from TRIM, as shown in the example. At a high level, this formula uses the LEN function to count the number of characters in the cell, with and without spaces, then uses the difference to figure out the word count. This works, because word count is equal to the number of spaces + 1, so long as there is one space between each word.

The first part of the formula counts the characters in cell B5, after removing extra space:

=LEN(TRIM(B5)) // normalize space, count characters

Inside LEN, the TRIM function first removes any extra spaces between words, or at the beginning or end of the text. This is important, since any extra spaces will throw off the word count. In this case, there are no extra space characters, so TRIM returns the original text directly to the LEN function, which returns 30:

LEN("All Quiet on the Western Front") // returns 30

At this point, we have:

=30-LEN(SUBSTITUTE(B5," ",""))+1

Next, we use the SUBSTITUTE function to remove all space characters from the text:

SUBSTITUTE(B5," ","") // strip all space

Notice SUBSTITUTE is configured to look for a space character (» «), and replace with an empty string («»). By default, SUBSTITUTE will replace all spaces. The result is delivered directly to the LEN function, which returns the count:

LEN("AllQuietontheWesternFront") // returns 25

LEN returns 25, the number of characters remaining after all space has been removed. We can now simplify the formula to:

=30-25+1 // returns 6

which returns 6 as a final result, the number of words in cell B5.

Dealing with blank cells

The formula in the example will return 1 even if a cell is empty, or contains only space. This happens because we are adding 1 unconditionally, after counting space characters between words. To guard against this problem, you can adapt the formula as shown below:

=LEN(TRIM(B5))-LEN(SUBSTITUTE(B5," ",""))+(LEN(TRIM(B5))>0)

Notice we’ve replaced 1 with this expression:

LEN(TRIM(B5))>0

This code first trims B5, then checks the length. If B5 contains text, LEN returns a positive number, and the expression returns TRUE. If B5 is empty, or contains only space, TRIM returns an empty string («») to LEN. In that case, LEN returns zero (0) and the expression returns FALSE. The trick is that TRUE and FALSE evaluate to 1 and zero, respectively, when involved in any math operation. As a result, the expression only adds 1 when there is text in B5. Otherwise, it adds zero (0). This logic could also be written with the IF function statement like this:

IF(LEN(TRIM(B5))>0,1,0)

and the result would be the same. The expression above is simply more compact.

Excel has built-in functions to count cells based on various condition(s). These include cells containing specific values like numbers, text, blank or non-blank values, and to calculate the length of a string. But unfortunately, there is no special built-in function to count words in Excel. This is possible, however, with the right formula.

How to count words in Excel

To count words in Excel, you need to use a special formula by combining various functions. Using a special formula you can easily count total words in a cell or range, and you can also count the number of times a word appears in a cell or range of cells. The formula for words count in a cell and range has some variations, such as;

  • If you need to count total words in a cell or number of times a word appears in a cell, then the formula would be a combination of LEN, TRIM and SUBSTITUTE functions.
  • But if you need to count total words in a range or the number of times a word appears in a range, then the formula would be a combination of SUMPRODUCT or SUM, LEN, TRIM and SUBSTITUTE functions.

In this article, you will learn how to count words in Excel. Excel word count could be in a cell or range, and you will also learn to count specific words in Excel appeared in a cell or range.

How to count total words in a cell

As explained above, to count total words in a cell you need to formulate a formula by combining LEN, TRIM and SUBSTITUTE functions as per the following syntax;

=LEN(TRIM(cell_ reference))-LEN(SUBSTITUTE(cell_ reference," ",""))+1

For example, to count words in cell A1, the formula would be;

=LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))+1

You need to copy down this formula to other rows that have text strings.

How this formula works

The TRIM function eliminates extra spaces at the start and end of a text string, and the LEN function calculates the total length of a string in cell A1 LEN(TRIM(A1)). It gives you the Total length of the string.

In the second step, SUBSTITUTE function replaces all the spaces with an empty text string (“”), and LEN function calculates the length of resulting string in cell A1LEN(SUBSTITUTE(A1,” “,””)). Final you add 1 to the final word count.

In simple words, this formula will calculate the word count in the following way;

=Total length of string – string length without spaces +1

= total words in a cell

For example, you have text strings in multiple cells, and you need to count total words in each cell. You need to apply this formula in the first cell and copy it down to other cells in rows to come up with the total word count, such as;

=LEN(TRIM(A2))-LEN(SUBSTITUTE(A2," ",""))+1

How to count specific words in a cell

If you need to count how many times a specific word appears in a cell, then you need to use the following formula as a combination of LEN, TRIM and SUBSTITUTE functions.

=(LEN(TRIM(cell_ref))-LEN(SUBSTITUTE(cell_ref,word,"")))/LEN(word)

You can enter the specific word directly in this formula or you can use cell reference where that word is stored and copy down the formula to other rows.

For example, you have a text string in cell A2 and a specific word stored in cell B1 then the formula would be;

=(LEN(TRIM(A2))-LEN(SUBSTITUTE(A2,$B$1,"")))/LEN($B$1)

Note: This formula is case-sensitive as SUBSTITUTE function is case-sensitive in Excel, so you need to be careful while entering specific words for the count in this formula.

How this formula works

In the first part, LEN and TRIM functions calculate the total length of the string in cell A2 “LEN(TRIM(A2))” after eliminating extra spaces at the start and end of the string to come up with the total length of the string.

In the second part, LEN and SUBSTITUTE functions calculate the length of the string after replacing the specific word with an empty text string “LEN(SUBSTITUTE(A2,” “,””))”.

Finally, you subtract the second part from the first part and divide the resulting figure by length of specific word string.  

In simple words, this formula will calculate the words count in the following way;

=(Total length of string – string length without a specific word)/Length of specific word

= Total specific words in a cell

For example, you want to count how many times a word “Excel” appears in each cell, and you will use the following formula for this purpose;

=(LEN(TRIM(A2))-LEN(SUBSTITUTE(A2,"Excel","")))/LEN("Excel")

How to count total words in a range

If you want to calculate total words in a range, then you need to use a formula as the combination of SUMPRODUCT or SUM, LEN, TRIM and SUBSTITUTE functions as per the following syntax;

=SUMPRODUCT(LEN(TRIM(range))-LEN(SUBSTITUTE(range," ",""))+1)

OR

=SUM(LEN(TRIM(range))-LEN(SUBSTITUTE(range," ",""))+1)

As you can see, this formula is same as of total words count in a cell, but it has additional SUMPRODUCT or SUM function to sum the resulting array of the word count in all the cells of a range.

The SUMPRODUCT function by default sums an array, so you need to enter it as usual by just pressing Enter key. But for the SUM function to sum an array, you need to convert the formula into an array formula by pressing Ctrl+Shift+Enter keys.

The formula to count total words in a range would be;

=SUMPRODUCT(LEN(TRIM(A2:A4))-LEN(SUBSTITUTE(A2:A4," ",""))+1)

How to count specific words in a range

When you need to count how many times a specific word appears in a range of cells then you need to use formula as per the following syntax;

=SUMPRODUCT((LEN(TRIM(range))-LEN(SUBSTITUTE(range,word,"")))/LEN(word))

Here, you only need to wrap the formula of specific word count in a cell into SUMPRODUCT or SUM function to sum the resulting array of specific word count in all the cells of range.

If you need to use SUMPRODUCT function, then use it as usual by pressing Enter key as it by default sums array. But if you use the SUM function to sum arrays, then you need to convert formula into an array by pressing Ctrl+Shift+Enter keys.

Here is the formula to count the specific word “Excel” in a range;

=SUMPRODUCT((LEN(TRIM(A2:A4))-LEN(SUBSTITUTE(A2:A4,"Excel","")))/LEN("Excel"))

Still need some help with Excel formatting or have other questions about Excel? Connect with a live Excel expert here for some 1 on 1 help. Your first session is always free. 

Понравилась статья? Поделить с друзьями:
  • Can you start a sentence with the word and or but
  • Can you count characters in word
  • Can you copyright the word the
  • Can you start a sentence with the word after
  • Can you split an excel cell