Pearson Software Consulting Services
Word Count
Unlike MS Word, Excel doesn't have a built in method for
counting the number of words in a spreadsheet. However, you can count the
number of words with a simple VBA macro.
|
|
|
|
||
To count the words in a single cell, you can use the
following formula: =IF(LEN(A1)=0,0,LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ",""))+1) This works by first using TRIM to convert multiple
spaces to single spaces and remove any leading or trailing spaces. Then it
subtracts from the Length of A1 the Length of A1 after all spaces have
been removed (SUBSTITUE). The difference is the number of spaces in
A1. Add 1 to that and you get the number of words. The same function in VBA
is shown below. Note that it uses Excel's worksheet function TRIM, not VBA's
Trim function. The two are not the same. Both functions remove leading and
trailing spaces, but Excel's TRIM changes multiple spaces within the string
to single spaces, while VBA's Trim function leaves multiple spaces within
the string intact. For example, |
||
Created By Chip Pearson and
Pearson Software Consulting, LLC
This Page:
Updated: November 06, 2013
MAIN PAGE
About This Site
Consulting
Downloads
Page Index
Search
Topic Index
What's New
Links
Legalese And Disclaimers
chip@cpearson.com
© Copyright 1997-2007 Charles H. Pearson