Bạn đang xem bài viết Excel Formula: Count Total Words In A Cell được cập nhật mới nhất tháng 12 năm 2023 trên website Hoisinhvienqnam.edu.vn. Hy vọng những thông tin mà chúng tôi đã chia sẻ là hữu ích với bạn. Nếu nội dung hay, ý nghĩa bạn hãy chia sẻ với bạn bè của mình và luôn theo dõi, ủng hộ chúng tôi để cập nhật những thông tin mới nhất.
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:
// 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:
"All Quiet on the Western Front"
// returns 30
At this point, we have:
Next, we use the SUBSTITUTE function to remove all space characters from the text:
// 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:
// returns 25
LEN returns 25, the number of characters remaining after all space has been removed. We can now simplify the formula to:
// 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:
Notice we've replaced 1 with this expression:
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:
and the result would be the same. The expression above is simply more compact.
How to Count Total Number of Words in a Cell of Excel?
The steps to count the total number of words in a cell of Excel are listed as follows:
Step 1: Select the cell in the Excel sheet where you want the result to appear.
Step 2: For counting the number of words in cell A1, enter the formula shown in the following image.
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 4: Drag the fill handle to all cells to get the word count of each cell.
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.
Step 1: Select the cell and enter the formula “=(LEN(cell)-LEN(SUBSTITUTE(cell,word,””)))/LEN(word)” as shown in the following image.
The result in cell A14 is 4.
The formula for counting the number of words in Excel is:
Let us understand the working of this formula.
To begin with, we utilize the SUBSTITUTE function to evacuate and displace all spaces in the cell with a vacant content string (“). The LEN function restores the length of the string without spaces.
Popular Course in this category
Further, we utilize the TRIM function 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.Characteristics of the Word Count Formula
The features of the word count formula are listed as follows:
It is not an in-built formula of Excel and needs to be entered manually.
It is not case sensitive which implies that any type of alphabetical letters can be used.
It is essential to place the $ sign to fix the cell reference while copying the formula.
It works well if the cell, for which the formula is being used, is checked beforehand.
It requires the correct range to be specified at the time of usage.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:
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:
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:
If the column is named “NamesColumn,” the cells in this column will use “NamesColumn” for reference.
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 a range of cells using Excel formulas (LEN, SUBSTITUTE, TRIM) along with practical examples and a downloadable Excel template. You may learn more about Excel from the following articles –
How to count the number of words in a cell or a range cells in Excel?
You can easily count the number of words in MS Word, but Excel doesn’t have a built-in tool for counting the number of words in a worksheet. However, you can count the number of words in Excel with following methods:
Here are two formulas for you to count words in a single cell and in a range cells.
Count words in a single cell
Please enter this formula =IF(LEN(TRIM(A2))=0,0,LEN(TRIM(A2))-LEN(SUBSTITUTE(A2,” “,””))+1) into the Formula Bar, and then press the Enter key.
Note: In the formula, A2 is the cell you will count number of words inside.
You can see the result as below screenshot shown:
Count words in a range of cells with array formula
If you want to count the words in a range of cells, please enter formula =SUM(IF(LEN(TRIM(A2:A3))=0,0,LEN(TRIM(A2:A3))-LEN(SUBSTITUTE(A2:A3,” “,””))+1)) into the formula bar, and then press the Shift + Ctrl + Enter keys simultaneously to get the result. See screenshot:
Note: A2:A3 is the range with words you will count.Count the number of words with User Defined Functions
Also, you can count the words in a cell with the User Defined Functions, please do as follows:
1. Press Alt + F11 keys together to open the Microsoft Visual Basic for applications window.
VBA code: Count number of words in a cell.Function intWordCount(rng As Range) As Integer 'Update by Extendoffice 2023/3/7 intWordCount = UBound(Split(Application.WorksheetFunction.Trim(rng.Value), " "), 1) + 1 End Function
2. Press the Alt + Q keys to close the Microsoft Visual Basic for Applications winodw. Select a blank cell in your worksheet, enter formula “=intwordcount(A2)” into the Formula Bar, and then press the Enter key to get the result. See screenshot:
Note: In the formula, A2 is the cell you will count number of words inside.
If you want to count number of words in a certain range, please apply the following method.Count number of words in specified range with VBA code
The following VBA code can help you quickly count number of words in a specified range.
1. Press Alt + F11 keys together to open the Microsoft Visual Basic for applications window.
VBA code: Count number of words in selected range.Sub CountWords() Dim xRg As Range Dim xRgEach As Range Dim xAddress As String Dim xRgVal As String Dim xRgNum As Long Dim xNum As Long On Error Resume Next xAddress = ActiveWindow.RangeSelection.Address Set xRg = Application.InputBox("Please select a range:", "Kutools For Excel", xAddress, , , , , 8) If xRg Is Nothing Then Exit Sub Application.ScreenUpdating = False If Application.WorksheetFunction.CountBlank(xRg) = xRg.Count Then MsgBox "Words In Selection Is: 0", vbInformation, "Kutools For Excel" Exit Sub End If For Each xRgEach In xRg xRgVal = xRgEach.Value xRgVal = Application.WorksheetFunction.Trim(xRgVal) xNum = Len(xRgVal) - Len(Replace(xRgVal, " ", "")) + 1 xRgNum = xRgNum + xNum End If Next xRgEach MsgBox "Words In Selection Is: " & Format(xRgNum, "#,##0"), vbOKOnly, "Kutools For Excel" Application.ScreenUpdating = True End Sub
Then another Kutools for Excel dialog box pops up to show you the total number of words in seleted range. See screenshot:
Before applying Kutools for Excel, please download and install it firstly.
2. In the Formulas Helper dialog box, please configure as follows.
In the Choose a formula box, select Count total words;Tips: You can check the Filter box, enter a key word to quickly filter the formula as you need.
In the Range box, specify the cell or range in which you want to count total words;
Then you will get the number of words in a specified cell or range.Easily count the number of words with Kutools for Excel
Kutools for Excel includes 300+ powerful features for Microsoft Excel. Free to try with no limitation in 30 days.Download now!
Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails…
More than 300 powerful features. Supports Office/Excel 2007-2023 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
Open and create multiple documents in new tabs of the same window, rather than in new windows.
This short tutorial explains the basics of the Excel COUNT and COUNTA functions and shows a few examples of using a count formula in Excel. You will also learn how to use the COUNTIF and COUNTIFS functions to count cells that meet one or more criteria.
As everyone knows, Excel is all about storing and crunching numbers. However, apart from calculating values, you may also need to count cells with values – with any value, or with specific value types. For example, you may want a quick count of all items in a list, or the total of inventory numbers in a selected range.
Microsoft Excel provides a couple of special functions for counting cells: COUNT and COUNTA. Both all very straightforward and easy-to-use. So let’s take a quick look at these essential functions first, and then I will show you a few Excel formulas to count cells that meet certain condition(s), and clue you in on the quirks in counting some value types.Excel COUNT function – count cells with numbers
You use the COUNT function in Excel to count the number of cells that contain numerical values.
The syntax of the Excel COUNT function is as follows:
COUNT(value1, [value2], …)
Where value1, value2, etc. are cell references or ranges within which you want to count cells with numbers.
In the modern versions of Excel 2023, Excel 2013, Excel 2010, and Excel 2007, the COUNT function accepts up to 255 arguments. In earlier Excel versions, you can supply up to 30 ‘values’.
For example, the following formula returns the total number of numeric cells in range A1:A100:
Note. In the internal Excel system, dates are stored as serial numbers and therefore the Excel COUNT function counts dates and times as well.Using COUNT function in Excel – things to remember
Below are the two simple rules by which the Excel COUNT function works.
If an argument(s) of an Excel Count formula is a cell reference or range, only numbers, dates and times are counted. Blanks cells and cells containing anything but a numeric value are ignored.
If you type values directly into the Excel COUNT arguments, the following values are counted: numbers, dates, times, Boolean values of TRUE and FALSE, and text representation of numbers (i.e. a number enclosed in quotation marks like “5”).
For example, the following COUNT formula returns 4, because the following values are counted: 1, “2”, 1/1/2023, and TRUE.
=COUNT(1, "apples", "2", 1/1/2023, TRUE)Excel COUNT formula examples
And here are a few more examples of using the COUNT function in Excel on different values.
To count cells with numeric values in one range, use a simple count formula like
The following screenshot demonstrates which types of data are counted and which are ignored:
To count several non-contiguous ranges, supply all of them to your Excel COUNT formula. For example, to count cells with numbers in columns B and D, you can use formula similar to this:
If you want to count numbers that meet certain criteria, use either the COUNTIF or COUNTIFS function.Excel COUNTA function – count cells with values (non-blank cells)
The COUNTA function in Excel counts the number of cells in a range that are not empty.
The syntax of the Excel COUNTA function is akin to that of COUNT:
COUNTA(value1, [value2], …)
Where value1, value2, etc. are cell references or ranges where you want to count non-blank cells.
For example, to count cells with value in range A1:A100, use the following formula:
To count non-empty cells in several non-adjacent ranges, use a COUNTA formula similar to this:
=COUNTA(B2:B10, D2:D20, E2:F10)
As you can see, the ranges supplied to an Excel COUNTA formula do not necessarily need to be of the same size, i.e. each range may contain a different number of rows and columns.
Please keep in mind that Excel’s COUNTA function counts cells containing any type of data, including:
Dates / times
Boolean values of TRUE and FALSE
Error values like #VALUE or #N/A
Empty text strings (“”)
In some cases, you may be perplexed by the COUNTA function’s result because it differs from what you see with your own eyes. The point is that an Excel COUNTA formula may count cells that visually look empty, but technically they are not. For example, if you accidentally type a space in a cell, that cell will be counted. Or, if a cell contains some formula that returns an empty string, that cell will be counted as well.
In other words, the only cells that the COUNTA function does not count are absolutely empty cells.
The following screenshot demonstrates the difference between Excel COUNT and COUNTA functions:
Tip. If you just want a quick count of non-blank cells in a selected range, simply have a look at Status Bar at the bottom right corner of your Excel window:
If you just want a quick count of, simply have a look at Status Bar at the bottom right corner of your Excel window:Excel COUNTIF function – count cells that meet one condition
The COUNTIF function is purposed for counting cells that meet a certain criterion. Its syntax requires 2 arguments, which are self-explanatory:
In the first argument, you define a range where you want to count cells. And in the second parameter, you specify a condition that should be met.
For example, to count how many cells in range A2:A15 are “Apples”, you use the following COUNTIF formula:
Instead if typing a criterion directly in the formula, you can input a cell reference as demonstrated in the following screenshot:
For more information about using the COUNTIF function in Excel, check out the following tutorial: COUNTIF in Excel – count if not blank, greater than, duplicate or uniqueExcel COUNTIFS function – count cells that match several criteria
The COUNTIFS function is similar to COUNTIF, but it allows specifying multiple ranges and multiple criteria. Its syntax is as follows:
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
The COUNTIFS function was introduced in Excel 2007 and is available in all later versions of Excel 2010, 2013, and 2023.
For example, to count how many “Apples” (column A) have made $200 and more sales (column B), you use the following COUNTIFS formula:
And again, to make your COUNTIFS formula more versatile, you can supply cell references as the criteria:
You will find plenty more formula examples here: How to use Excel COUNTIFS function with multiple criteria.Count the number of cells in a range (ROWS and COLUMNS functions)
If you need to find out the total number of cells in a rectangular range, utilize the ROWS and COLUMNS functions, which return the number of rows and columns in an array, respectively:
For example, to find out how many cells there are in a given range, say A1:D7, use the following formula:
=ROWS(A1:D7)*COLUMNS(A1:D7)You may also be interested in
First, let’s count the total number of words in a cell or range of cells. Finally, let’s count how many times a specific word occurs in a cell or range of cells.
1. The TRIM function below returns a string with only regular spaces.
2. To get the length of this string, add the LEN function.
3. The SUBSTITUTE function below returns a string without spaces.
4. To get the length of this string, add the LEN function.
5. To count the total number of words in cell A1, subtract the length of the string without spaces (formula from step 4) from the length of the string with only regular spaces (formula from step 2) and add 1.
Conclusion: to count the total number of words in a cell, simply count the number of spaces and add 1 to this result. 1 space means 2 words, 2 spaces means 3 words, etc.
6. To count the total number of words in the range A1:A2, add the SUMPRODUCT function and replace A1 with A1:A2.
Note: visit our page about the SUMPRODUCT function to learn more about this Excel function.
Finally, let’s count how many times a specific word occurs in a cell or range of cells. This trick is pretty cool.
7. The LEN function below returns the length of the original text in cell A1.
8. The SUBSTITUTE function below returns the string without the word “dog”.
9. The LEN function below returns the length of this string.
10. Subtract the length of the string without the word “dog” (formula from step 9) from the length of the original text in cell A1 (formula from step 7).
Conclusion: after removing the word “dog” from the original text, 12 characters are missing.
11. We know the length of the word “dog” (3), so the word “dog” occurs 12 / 3 = 4 times in cell A1.
12. To count how many times the word “dog” occurs in the range A1:A2, add the SUMPRODUCT function and replace A1 with A1:A2.
13. Use the COUNTIF function in Excel to count the number of cells that contain a specific word.
Note: an asterisk (*) matches a series of zero or more characters. Visit our page about the COUNTIF function to learn more about this great Excel function.
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:
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:
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
Cập nhật thông tin chi tiết về Excel Formula: Count Total Words In A Cell trên website Hoisinhvienqnam.edu.vn. Hy vọng nội dung bài viết sẽ đáp ứng được nhu cầu của bạn, chúng tôi sẽ thường xuyên cập nhật mới nội dung để bạn nhận được thông tin nhanh chóng và chính xác nhất. Chúc bạn một ngày tốt lành!