# How to count the number of words in a range of cells in Excel

In the previous post, we talked that how to count the number of words in a single cell. And this post explains that how to count the number of words in a range of cells using excel formula. And how to count the total words in a range of cell with VBA Code.

## Count the number of words in a range of cells

If you want to count the number of words in a range of cell, you need to use a combination of the SUMPRODUCT function, the IF function, the LEN function, the TRIM function and the SUBSTITUTE function to create an excel formula.

You need to use the SUBSTITUTE function to remove all spaces from the text for each cell in the range, then using LEN function to calculate the length of the text without spaces. The returned number is subtracted from the length of the text string with space characters to get the number of spaces in the text. And then add 1 to get the number of words in the range.

Assuming that you want to count the number of words in the range B1:B3, you can write down an excel array formula as follows:

`=SUMPRODUCT(IF(LEN(TRIM(B1:B3))=0, 0, LEN(TRIM(B1:B3))-LEN(SUBSTITUTE(B1:B3," ", ""))+1))`

Let’s see how this formula works:

=LEN(TRIM(B1:B3))-LEN(SUBSTITUTE(B1:B3,” “, “”))+1 This formula returns an array result that contains a number of words for each cell in the range. The array result is like this: {4;2;2}, then it goes into the IF function as its argument.

=IF(LEN(TRIM(B1:B3))=0, 0, LEN(TRIM(B1:B3))-LEN(SUBSTITUTE(B1:B3,” “, “”))+1)

The IF function will check if it is an empty cell, if TRUE, then returns 0, otherwise, returns the number of words in the text in cell.

=SUMPRODUCT() This formula will sum all items in that array result that returned by the IF formula to get the total number of words in the range B1:B3.

## Count the number of words in a range of cells with VBA Code

You can also create a new user defined function to count the number of words in a range in Excel VBA:

1# click on “Visual Basic” command under DEVELOPER Tab. 2# then the “Visual Basic Editor” window will appear.

3# click “Insert” ->”Module” to create a new module 4# paste the below VBA code into the code window. Then clicking “Save” button. ```Sub CountTotalWordsRange()
Set myRange = Application.InputBox("Please select a range that you want to count words:", "CountTotalWordsRange", myAddress, , , , , 8)
If myRange Is Nothing Then Exit Sub
If Application.WorksheetFunction.CountBlank(myRange) = myRange.Count Then
MsgBox "the number of words is: 0", vbInformation, "CountTotalWordsRange"
Exit Sub
End If

For Each myCell In myRange
cValue = myCell.Value
cValue = Application.WorksheetFunction.Trim(cValue)
If myCell.Value <> "" Then
xNum = Len(cValue) - Len(Replace(cValue, " ", "")) + 1
cNum = cNum + xNum
End If
Next myCell
MsgBox "the number of words Is: " & Format(cNum, "#,##0"), vbOKOnly, "CountTotalWordsRange"
End Sub```

5# back to the current worksheet, then run the above excel macro, then select a range that you want to count the number of words.   ### Related Formulas

• count specific words in a cell or a range
If you want to count the number of a specific word in a single cell, you need to use the SUBSTITUTE function to remove all that certain word in text string, then using LEN function to calculate the length of the substring that without that specific word.…
• Count the number of words in a cell
If you want to count the number of words in a single cell, you can create an excel formula based on the IF function, the LEN function, the TRIM function and the SUBSTITUTE function. ..
• Extract word that starting with a specific character
Assuming that you have a text string that contains email address in Cell B1, and if you want to extract word that begins with a specific character “@” sign, you can use a combination with the TRIM function, the LEFT function, the SUBSTITUTE function, the MID function, the FIND function, the LEN function and the REPT function to create an excel formula.…

### Related Functions

• Excel SUMPRODUCT function
The Excel SUMPRODUCT function multiplies corresponding components in the given one or more arrays or ranges, and returns the sum of those products.The syntax of the SUMPRODUCT function is as below:= SUMPRODUCT (array1,[array2],…)…
• Excel Substitute function
The Excel SUBSTITUTE function replaces a new text string for an old text string in a text string.The syntax of the SUBSTITUTE function is as below:= SUBSTITUTE  (text, old_text, new_text,[instance_num])….
• Excel IF function
The Excel IF function perform a logical test to return one value if the condition is TRUE and return another value if the condition is FALSE. The IF function is a build-in function in Microsoft Excel and it is categorized as a Logical Function.The syntax of the IF function is as below:= IF (condition, [true_value], [false_value])….
• Excel LEN function
The Excel LEN function returns the length of a text string (the number of characters in a text string).The syntax of the LEN function is as below:= LEN(text)…
• Excel TRIM function
The Excel TRIM function removes all spaces from text string except for single spaces between words. The syntax of the TRIM function is as below:=TRIM(text)…
Related Posts
VBA Macro For VLOOKUP From Another Sheet

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Insert Comments in Protected Worksheet in Excel

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How To Hide Every Other Row in Excel (Using VBA)

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how ...

How to Disable the Save As Prompt in Excel

This post will show you how to use a VBA Macro to save an Excel file and overwrite any existing file without a prompt so that you are going to get the little window that says file already exists do ...

How to Count Cells that Contain even or odd numbers in Excel

This post will guide you how to count the number of cells that contain odd or even numbers within a range of cells using a formula in Excel 2013/2016.How do I count cells that contain odd numbers through the use ...

How to Count Cells that Contain negative Numbers in Excel

This post will guide you how to count the number of cells that contain negative numbers within a range of cells using a formula in Excel 2013/2016.You can count the number of negative numbers in your data using easy functions ...

How to Count Cells Are Not Blank or Empty in Excel

This post will guide you how to count cells that are not blank or empty in a given range cells using a formula in Excel 2013/2016.How do I count the number of cells that are not blank in a particular ...

How to Count Cells Not equal to X or Y in Excel

This post will guide you how to count the number of cells not equal to criteria X or Y in a given range cells using a formula in Excel 2013/2016.You can easily to count cells equal to or not equal ...

How to Count Cells Less Than a Specific Value in Excel

This post will guide you how to count the number of cells less than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are less than a specific ...

Sidebar