+ Reply to Thread
Results 1 to 7 of 7

Is this possible?? Find most commonly occurring words in a cell

  1. #1
    Registered User
    Join Date
    05-22-2014
    Posts
    20

    Is this possible?? Find most commonly occurring words in a cell

    Hi there

    I was wondering if anyone knows how to find the most commonly occurring 10 words in a cell? If there is a tie meaning that there would be more than 10 words, then show all of those that are tying (i.e 9 words appear 3 times and 4 words appear twice = show 13 words)

    All words in the cell are separated by a space

    Thanks very much

    Luke

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,301

    Re: Is this possible?? Find most commonly occurring words in a cell

    With VBA, almost anything is possible.


    Copy the code below into a standard codemodule, and use it like

    =TopWords(B2)

    to return just the list of words like

    a in an or to on at of and if you

    or to return fewer than 10

    =TopWords(B2,5)
    a in an or to

    or to a list showing the counts, use it like this

    =TopWords(B2,,TRUE)

    which will return

    190: a 31: in 28: an 27: or 25: to 24: on 20: at 18: of 16: and 15: if you

    And if you want to only look at longer words, use it like

    =TopWords(B2,,TRUE, 4)

    which will return, for example, only words that are 4 characters or longer

    12: test 11: your 10: vacuum 7: window roof with 6: fork 4: attached which valve used hold

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 08-28-2014 at 11:57 AM.
    Bernie Deitrick
    Excel MVP 2000-2010

  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: Is this possible?? Find most commonly occurring words in a cell

    Hi,

    Based on a string in A1, first go to Name Manager (Formulas tab) and create the following, making sure that the active cell in the worksheet at the time you do so is somewhere in row 1 (or, if the string in question is not in row 1, than in whatever row that string does happen to be):

    Name: Arry1
    Refers to: =ROW(INDIRECT("1:"&1+LEN($A1)-LEN(SUBSTITUTE($A1," ",""))))

    Name: Arry2
    Refers to: =TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",LEN($A1))),LEN($A1)*(Arry1-1)+1,LEN($A1)))

    Name: Arry3
    Refers to: =LEN($A1)-LEN(SUBSTITUTE($A1,Arry2,""))

    Exit Name Manager.

    Enter this array formula** in B1:

    =SUM((0+(IF(FREQUENCY(MATCH(Arry2,Arry2,0),Arry1),Arry3,0)>=LARGE(IF(FREQUENCY(MATCH(Arry2,Arry2,0),Arry1),Arry3),10))))

    Then this array formula** in C1:

    =IF(COLUMNS($A:A)>$B$1,"",INDEX(Arry2,MATCH(LARGE(IF(FREQUENCY(MATCH(Arry2,Arry2,0),Arry1),Arry3+Arry1/10^9),COLUMNS($A:A)),Arry3+Arry1/10^9,0)))

    Copy this formula to the right (though obviously not the one in B1) until you start to get blanks for the results.

    It can also be copied down to give similar results for strings in A2, A3, etc.

    Note that this solution depends on, as you say, the individual words in that string being separated by a single space precisely.

    Also, you don't mention what should be the result in the case that there are less than 10 unique words within the string, so no accounting for this has been made (the formulas will currently error).

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
    Last edited by XOR LX; 08-28-2014 at 11:41 AM.
    Click * below if this answer helped

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

  4. #4
    Valued Forum Contributor TheCman81's Avatar
    Join Date
    11-06-2012
    Location
    Edinburgh, UK
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    346

    Re: Is this possible?? Find most commonly occurring words in a cell

    Please see the attache sdheet, this is an array formula and required Ctrl Shift Enter to submit

    Top 10 most freq numbers.xlsx
    Excel Guru in the making

    <----------If the question has been answered to your satisfication please click the Add Repuation star to the left

  5. #5
    Registered User
    Join Date
    05-22-2014
    Posts
    20

    Re: Is this possible?? Find most commonly occurring words in a cell

    Wow, thank you very much, this seems to have solved the problem! Best regards and thanks for all your help, Luke

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

    Re: Is this possible?? Find most commonly occurring words in a cell

    Quote Originally Posted by TheCman81 View Post
    Please see the attache sdheet, this is an array formula and required Ctrl Shift Enter to submit

    Attachment 341951
    I hope I didn't misunderstand the question, then? I thought we were talking about entries in a single cell?

    Regards

  7. #7
    Valued Forum Contributor TheCman81's Avatar
    Join Date
    11-06-2012
    Location
    Edinburgh, UK
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    346

    Re: Is this possible?? Find most commonly occurring words in a cell

    Quote Originally Posted by XOR LX View Post
    I hope I didn't misunderstand the question, then? I thought we were talking about entries in a single cell?

    Regards
    I missed the part were it said cell.

+ 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. Display most commonly occurring text, IF text occurs more than X times
    By Kpolly in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-04-2014, 02:24 PM
  2. Replies: 5
    Last Post: 10-17-2013, 08:03 PM
  3. Replies: 3
    Last Post: 11-28-2012, 04:00 AM
  4. Replies: 2
    Last Post: 09-09-2011, 05:07 PM
  5. Count and identify most frequently occurring words
    By SueWithQuestion in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-24-2011, 01:25 PM

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