Results 1 to 13 of 13

Count unique words appearing in a column once per row

Threaded View

  1. #1
    Registered User
    Join Date
    01-04-2010
    Location
    Canberra, Australia
    MS-Off Ver
    Excel 2007
    Posts
    11

    Count unique words appearing in a column once per row

    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.
    Attached Files Attached Files
    Last edited by eq2; 01-20-2010 at 08:17 AM.

Thread Information

Users Browsing this Thread

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

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