Finding most common words in excel

Joshyd

New Member
Joined
Mar 6, 2019
Messages
17
Hi there,

I have several survey question responses. Many of them are paragraphs in single cells. I am wondering if there is a way for excel to look at every word (not just the cell as a whole) and return the most common words.

The problem I am running into is that I want to look at each word, which may be many in a single cell as opposed to the whole cell value. This is because essentially all the cells are unique values. I am not yet sure how many top words I would need (depends on the results). If any suggestions included an easy way to modify the number of words returned, that would be awesome.

Many thanks in advance.
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,589
Office Version
365
Platform
Windows
Which cells contain your paragraphs?
 

Joshyd

New Member
Joined
Mar 6, 2019
Messages
17
There are a lot of them, D2:BY60, but I would like to do the search by column.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,589
Office Version
365
Platform
Windows
Ok, how about this
Code:
Sub Joshyd()
    Dim Ary As Variant, Sp As Variant, Elmt As Variant
    Dim r As Long, c As Long
    
    Ary = Sheets("[COLOR=#ff0000]Sheet1[/COLOR]").Range("D2:BY60").Value2
    With CreateObject("scripting.dictionary")
        For c = 1 To UBound(Ary, 2)
            For r = 1 To UBound(Ary)
                For Each Elmt In Split(Ary(r, c))
                    .Item(Elmt) = .Item(Elmt) + 1
                Next Elmt
            Next r
            If .Count > 0 Then Sheets("[COLOR=#ff0000]Sheet2[/COLOR]").Cells(2, c * 2 - 1).Resize(.Count, 2).Value = Application.Transpose(Array(.Keys, .Items))
            .RemoveAll
        Next c
    End With
End Sub
Change sheet names to suit.
The 2nd sheet (sheet2 in the code) is where it will output the results
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
10,192
Office Version
2007
Platform
Windows
Try this, The result on the same sheet in the columns CA y CBCheck the result and you can order the number of words from highest to lowest.

Code:
Sub Finding_most_common_words()
  Dim c As Range, w As Variant, dict As Object
  Set dict = CreateObject("scripting.dictionary")
  For Each c In Range("D2:BY60")
    For Each w In Split(c, " ")
      dict(w) = Val(dict(w)) + 1
    Next
  Next
  Range("CA2").Resize(dict.Count) = Application.Transpose(dict.Keys)
  Range("CB2").Resize(dict.Count) = Application.Transpose(dict.Items)
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,589
Office Version
365
Platform
Windows
Glad you were able to sort it & thanks for the feedback
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
10,192
Office Version
2007
Platform
Windows
I'm glad to help you. Thanks for the feedback.
 

Forum statistics

Threads
1,089,382
Messages
5,407,929
Members
403,172
Latest member
kanth1999

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top