|
Count The Number of Words in a Cell or Range of Cells in Excel - With User-Specified Delimiter / Separator - UDF
UDF to count the number of words in a cell or range with a user-specified delimiter. This means that you can tell the function what separates the words in your cells in Excel. For example, if you have words separated by a dash or a period etc., you can tell this function that that character separates your words and the words will then be counted correctly. This UDF counts words in a single cell and words in a range of cells in Excel.
The separator argument is optional. If you leave the separator argument blank, the function will default to use a space as the separator.
Where to install the macro: Module
UDF to Count The Number of Words in a Cell or Range of Cells in Excel - With User-Specified Delimiter / Separator
Function COUNTWORDSC(rRange As Range, Optional separator As Variant) As Long
Dim rCell As Range
Dim Count As Long
If IsMissing(separator) Then
separator = " "
End If
For Each rCell In rRange
lCount = lCount + Len(Trim(rCell)) - Len(Replace(Trim(rCell), separator, "")) + 1
Next rCell
COUNTWORDSC = lCount
End Function
How to Install the Macro
- Select and copy the text from within the grey box above.
- Open the Microsoft Excel file in which you would like the Macro to function.
- Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.
Or For other ways to get there, Click Here.
For Excel Versions Prior to Excel 2007 Go to Tools > Macros > Visual Basic Editor
For Excel 2007 Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic
- On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.
- If the Macro goes in a Module, Click Here, otherwise continue to Step 8.
- Go to the menu at the top of the window and click Insert > Module
- Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
- Go to Step 8.
- If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Go to Step 8.
- If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.
- Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
- Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
- A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
- Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
- Go to Step 8.
- Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.
- You are now ready to run the macro.
Similar Helpful Excel Resources
I am importing data from a survey in which some questions had multiple
options, when this is imported to excel multiple entries are seperated by
commas in the same cell and this continues down the column. Is it possible
to get excel to search cells for specific words within it and total their
occurence?
Hi.. how do I go about counting the number of cells between two words?
I have multiple words (e.g., DM, DG) arranged in a column and in chronological order (as below). How do I count the number of blank/empty only cells between two words (i.e., between the first DM and DG?
Also how do I count all cells (with or without text) between DM and DG? Thanks v much.
11-Nov-10
29-Oct-10 DM
30-Sep-10 RL
31-Aug-10
31-Jul-10 DG
30-Jun-10
31-May-10
30-Apr-10 DM
31-Mar-10
Hi,
I am trying to write a macro that counts the number of words in a text.
For example
input
Column A
one two
one two three
one two three
one
...
output
Column B
2
3
3
1
...
I have the macro button on sheet1 and the columns will be on sheet3.
So when I click the macro button, which is on sheet1, it will get the number of words in column A of sheet3 and output it into column B of sheet3.
Any ideas?
I know the formula
Code:
=IF(LEN(TRIM(A2))=0;0;LEN(TRIM(A2))-LEN(SUBSTITUTE(A2;" ";""))+1)
which I use without a macro.
Is there a formula to count how many words are in a cell? (Like LEN counts the characters)
I have a cell that contains first middle and last name. Sometimes they have more than one middle name and I want to know exactly how many names that person has.
Any help appreciated.
Thanks
DJL
I need a macro to count the number of words in cell A1 sheet1.
Failed example:
Code:
sub countwordsincell()
msgbox countwords(range("a1"))
end sub
Words in cell a1 = "Only if we had a macro to count words"
results:
msgbox says 9
Thanks!
Nicole
I don't know if this is a 'count' formula or not, but i want to count the number of times a specific word is displayed in a cell range.
for example the cell range is A4:C10 and the word is 'hello'
cheers,
1.zer0
I have a worksheet and want to count the number of words, say, ABC, in the cell range, say, A1:B5.
Any function/formulas that can help this count?
Hi,
Suppose in cell A1 I have a text --- "I had some bread in morning. I had
some eggs at night."
Is it possible to programmatically get a count of unique words in the above
string.
Like in column B the unique words are listed one word in each row in the
following manner..B1 -- "I"
B2 -- "I
B2 -- "had
B3 -- "some"
B4 -- "bread"
B5 -- "in"
B6 -- "morning"
B7 -- "eggs"
B8 -- "at"
B9 -- "night"
Actually I can use excel's text to columns feature ( using space as a
delimiter) but automating is a problem. Like I have 500 or so rows of data
and out of those rows I want to get count of unique words within those 500
rows ( basically a consolidated unique list..). Now, each row would be
having different number of words so, programmatically how would it be
implemented.
Please guide me if possible.
Regards,
Hari
India
Is there a formula or a function that I could use to take a range of cells and have them all in one cell seperated by a semi colon. So d1 is me@mail.com and d2 is you@mail.com and d3 is them@mail.com. I would like d4 to be me@mail.com; you@mail.com; them@mail.com. The range is about 183 rows or else I would just use =d1 &";" & d2 &"; " & d3.
Any suggestions?
What is my limit for charcters per cell? If I merge 2 cells would that double the max characters allowed?
Hey everyone,
I'm working on a project and need some assistance. Using Excel 2007, how do I add up the total of the word "apples" to a cell.
Example: If Cell A1,A10,A25,A30 all have the word apple entered, how do I add them up in lets say cell B10.
Also, I need to do it where I can enter multiple words in 1 cell and have it organized according to how many times the word is used.
Thanks in advance!
|
|