I would like to modify the below macro so it only counts a word once even if it appears more than once in a row. The reason I want to do this is so I can get a snapshot of the data without certain terms being over-represented.
For example, in the attached example the word 'Microsoft' appears 5 times in row 4 but I only want this to be counted once. In the whole data set Microsoft appears 20 times but only in 7 of the 20 rows so I would like the count to be 7.
The example is set out as follows: In column B there is a description field which in practice will contain consumer complaints and inquiries. To keep the data anonymous the description is filled out with random words and all other columns are blank. The output of Andy Pope's unique word counting macro appears in I:J.
Sub CreateUniqueWords()
Dim rngData As Range
Dim rngCell As Range
Dim colWords As Collection
Dim vntWord As Variant
On Error Resume Next
Set colWords = New Collection
Set rngData = Range("B4:B24")
For Each rngCell In rngData.Cells
For Each vntWord In Split(Replace(Replace(Replace(rngCell.Value, """", ""), "]", ""), "[", ""), " ")
colWords.Add colWords.Count + 1, vntWord
With Cells(3 + colWords(vntWord), 9)
.Value = vntWord
.Offset(0, 1) = .Offset(0, 1) + 1
End With
Next
Next
With Range("I4", Cells(Rows.Count, 9).End(xlUp)).Resize(, 2)
.Sort .Cells(1, 2), xlDescending
End With
End Sub
I have been advised by a mod to start a new thread as the goals of my previous thread had changed.
Bookmarks