Results 1 to 15 of 15

Trying to find the most common word in a very large list

Threaded View

Flying_Dutchman Trying to find the most... 07-10-2012, 08:01 AM
rkey Re: Trying to find the most... 07-10-2012, 08:36 AM
Flying_Dutchman Re: Trying to find the most... 07-10-2012, 09:04 AM
jindon Re: Trying to find the most... 07-10-2012, 08:57 AM
Flying_Dutchman Re: Trying to find the most... 07-10-2012, 09:08 AM
jindon Re: Trying to find the most... 07-10-2012, 09:12 AM
Flying_Dutchman Re: Trying to find the most... 07-10-2012, 09:23 AM
Flying_Dutchman Re: Trying to find the most... 07-10-2012, 09:27 AM
jindon Re: Trying to find the most... 07-10-2012, 09:38 AM
Flying_Dutchman Re: Trying to find the most... 07-10-2012, 09:52 AM
jindon Re: Trying to find the most... 07-10-2012, 10:12 AM
Flying_Dutchman Re: Trying to find the most... 07-10-2012, 10:14 AM
jindon Re: Trying to find the most... 07-10-2012, 10:18 AM
Flying_Dutchman Re: Trying to find the most... 07-10-2012, 10:21 AM
jindon Re: Trying to find the most... 07-10-2012, 10:23 AM
  1. #1
    Registered User
    Join Date
    07-10-2012
    Location
    Verenigde Staten
    MS-Off Ver
    Excel 2010
    Posts
    11

    Trying to find the most common word in a very large list

    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.
    Last edited by JBeaucaire; 07-10-2012 at 08:19 AM. Reason: added code tags as per forum rules, don't forget next time. Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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