Akuini

VBA Macro to create Word & Phrase Frequency

@CarolynV, welcome to MrExcel.
However, is there a way to limit it from running into the next cell in the column when counting occurences of phrases?
Run this following macro "Sub add_end_of_line".
VBA Code:
Sub add_end_of_line()
'this will add a dot at the end of every cell value.
Dim va
Dim i As Long
va = Range("A1", Cells(Rows.Count, "A").End(xlUp))
For i = 1 To UBound(va, 1)
    va(i, 1) = va(i, 1) & "."
Next
Range("A1").Resize(UBound(va, 1), 1) = va
End Sub
It will append a dot to the end of each cell value, thereby restricting a phrase to include only the value from a single cell.
After that, run "Sub Word_Phrase_Frequency_v1".
 
@CarolynV
Using your example, here's the result:
dhee - Macro to create Word & Phrase Frequency 1.xlsm
ABCDEFG
1faulty replacement required.3 WORDCOUNT4 WORDCOUNT
2replacement item ordered.faulty replacement required1item sent to customer1
3Loan item sent to customer.item sent to1Loan item sent to1
4Loan item sent1
5replacement item ordered1
6sent to customer1
Sheet1
 
@CarolynV
Using your example, here's the result:
dhee - Macro to create Word & Phrase Frequency 1.xlsm
ABCDEFG
1faulty replacement required.3 WORDCOUNT4 WORDCOUNT
2replacement item ordered.faulty replacement required1item sent to customer1
3Loan item sent to customer.item sent to1Loan item sent to1
4Loan item sent1
5replacement item ordered1
6sent to customer1
Sheet1
Absolutely amazing. Thank you so much.
 
This code has been really useful. However, is there a way to limit it from running into the next cell in the column when counting occurences of phrases? I have a list of free text entries (60k rows), and wish to identify the most frequent 3-word and 4-word groups. At the moment, the return is skewed as the analysis includes the cell below. For example, the following cells would return the phrase "replacement required replacement".

faulty replacement required
replacement item ordered
Loan item sent to customer

I appreciate this thread is old, but it is a really useful piece of code and your assistance would be greatly appreciated.

Can't believe I never noticed it did this. I've been using this code for a couple years with some of my own mods and love it.
Easiest fix is to find this block of logic where it is building the combined string of all phrases and put a delimiter in there in place of the space.
Basically, replace " " with "|" (see bolded logic below)

If j < 65000 Then
txa = Join(Application.Transpose(Range("A1", Cells(Rows.Count, "A").End(xlUp))), "|")
Else
For i = 1 To j Step 65000
txa = txa & Join(Application.Transpose(Range("A" & i).Resize(65000)), "|") & "|"
Next
End If
 

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top