So I have a worksheet with 100+ entries, each of which have from 20-1000 characters, usually <100 words. My goal is to get a list of most common words in these entries and how commonly they are used.
so far my code looks like this:
Sub word_splitter()
Dim counterArray As Variant
Dim dictionary As Variant
Dim partialList As Variant
Dim wordList As Variant
Dim counter As Double
Dim counter2 As Double
Dim length1 As Double
Dim length2 As Double
Dim check As Integer
ReDim partialList(0 To 0)
ReDim wordList(0 To 0)
For Each rCell In Range("b2", "b9")
partialList = Split(rCell, " ")
For counter = 0 To UBound(partialList)
length2 = UBound(partialList)
length1 = UBound(wordList)
ReDim Preserve wordList(length1 + 1)
wordList(length1) = partialList(counter)
Next counter
Next rCell
For counter = 0 To UBound(wordList)
Range("c1").Offset(counter, 0) = wordList(counter)
Next counter
ReDim counterArray(0 To 0)
ReDim dictionary(0 To 0)
For counter = 0 To UBound(wordList)
check = 0
length2 = UBound(wordList)
length1 = UBound(dictionary)
ReDim Preserve dictionary(0 To length1 + 1)
ReDim Preserve counterArray(0 To length1 + 1)
For counter2 = 0 To length1
If dictionary(counter2) = wordList(counter) Then
counterArray(counter2) = counterArray(counter2) + 1
check = 1
End If
Next counter2
If check = 0 Then
dictionary(length1) = wordList(counter)
End If
Next counter
For counter = 0 To UBound(dictionary)
Range("d1").Offset(counter, 0) = dictionary(counter)
Next counter
For counter = 0 To UBound(counterArray)
Range("e1").Offset(counter, 0) = counterArray(counter)
Next counter
End Sub
it works okay for a few entries but any more than 8 entries and it breaks. It gives me "Run-time error 1004: application-defined or object-defined error". Any help would be much appreciated.
Bookmarks