+ Reply to Thread
Results 1 to 12 of 12

How to count the number of words in a cell with line breaks?

  1. #1
    Registered User
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2003
    Posts
    9

    How to count the number of words in a cell with line breaks?

    Hi,

    I am making a content database and need to count the number of words in each cell...

    I know you can count them with

    =IF(LEN(TRIM(A2))=0,0,LEN(TRIM(A2))-LEN(SUBSTITUTE(A2,” “,””))+1)

    but the the cells have line breaks so this formula won't work

    I've understood that since there is a space before the new line, the formula will not recognise the space and therefore not recognise a new word.

    Any ideas on how I can work this out?

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How to count the number of words in a cell with line breaks?

    Count the line breaks as well as the spaces, by substituting char(10):
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to count the number of words in a cell with line breaks?

    Hi,

    =IF(LEN(TRIM(A2))=0,0,LEN(TRIM(A2))-LEN(SUBSTITUTE(SUBSTITUTE(TRIM(A2),CHAR(10),"")," ",""))+1)

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  4. #4
    Registered User
    Join Date
    06-06-2014
    Posts
    1

    Re: How to count the number of words in a cell with line breaks?

    i want to collect a particular cell content of different worksheets of a same workbook. can any one help me?

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How to count the number of words in a cell with line breaks?

    Quote Originally Posted by rajancce View Post
    i want to collect a particular cell content of different worksheets of a same workbook. can any one help me?
    Start your own thread.

  6. #6
    Registered User
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: How to count the number of words in a cell with line breaks?

    I tried both Olly's and XOR LX's functions but I get the same as number of words as I did with the my original function.

    I've noticed that for every line break, there's a word that isn't counted.

    An example of cell would be:

    Question: How old are you?
    1.How old are you?*
    2. How are you?

    All functions proposed so give me 13, but there are 15.

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to count the number of words in a cell with line breaks?

    Sorry - how do you get 15 there?

    Regards

  8. #8
    Registered User
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: How to count the number of words in a cell with line breaks?

    The numbers should be included in the word count, sorry for not clarifying that.

    But for another example:

    "Listen to these two sentences:
    How old is he?
    He’s forty."

    I get 9 words when it should be 11.
    I know it's because of the line breaks. I've used ALT RETURN to create new lines...

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to count the number of words in a cell with line breaks?

    I get 11 with the formula I posted.

    Perhaps there's some other characters in there? Maybe a workbook would help?

    Regards

  10. #10
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: How to count the number of words in a cell with line breaks?

    Quote Originally Posted by XOR LX View Post
    I get 11 with the formula I posted.

    Perhaps there's some other characters in there? Maybe a workbook would help?
    Same with mine.

  11. #11
    Registered User
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: How to count the number of words in a cell with line breaks?

    I opened a new sheet but still the same problem. Any suggestions? I'm a bit of newbie at excel

  12. #12
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to count the number of words in a cell with line breaks?

    Like I said - I think you need to upload an actual workbook which illustrates this issue so we can take a look.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Count the number of words in a cell separated with with two different signs
    By Lija in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-30-2013, 06:11 AM
  2. Line breaks in a cell
    By nugentd1 in forum Excel General
    Replies: 1
    Last Post: 09-23-2011, 10:31 AM
  3. Count words-I want a function that can count the words in a cell
    By wilhelm in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-19-2009, 03:41 PM
  4. Replies: 4
    Last Post: 07-18-2006, 01:05 PM
  5. How do I count the number of words in a cell?
    By Phil in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-02-2006, 02:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1