Got any Excel/VBA Questions? Excel Help.
CountWords Function will count words in single cell, or range of cells.
The Code
Function CountWords(rRange As Range) As Long
Dim rCell As Range, lCount As Long
'''''''''''''''''''''''''''''''''''''''''
'Written by Ozgrid.com'''''''''''''''''''
'Count whole words
'''''''''''''''''''''''''''''''''''''''''
For Each rCell In rRange
lCount = lCount + _
Len(Trim(rCell)) - Len(Replace(Trim(rCell), " ", "")) + 1
Next rCell
CountWords = lCount
End Function
To use this UDF push Alt+F11 and go Insert>Module and paste in the code. Push Alt+Q and save. The Function will appear under "User Defined" in the Paste Function dialog box (Shift+F3). Use the Function in any cell as shown below.
=CountWords(A1) OR =CountWords(A1:A10).
See also:
Count Or Sum Specified Number In a Single Cell |
VBA Count of Each Item in a List |
Count Distinct Values Once/Count Repeated Entries Only One Time |
Free Training Course: Lesson 1 - Excel Fundamentals
See also: Index to Excel VBA Code; Index to Excel Freebies; Lesson 1 - Excel Fundamentals; Index to how to… providing a range of solutions
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.