Results 1 to 9 of 9

VBA "Scripting.Dictionary" Word Occurences under each category

Threaded View

manofcheese VBA "Scripting.Dictionary"... 07-17-2015, 04:39 PM
tfurnivall Re: VBA... 07-17-2015, 05:59 PM
Leith Ross Re: VBA... 07-18-2015, 03:23 PM
manofcheese Re: VBA... 07-20-2015, 10:26 AM
Leith Ross Re: VBA... 07-21-2015, 12:46 AM
manofcheese Re: VBA... 07-23-2015, 01:37 PM
jindon Re: VBA... 07-21-2015, 02:30 AM
manofcheese Re: VBA... 07-23-2015, 01:41 PM
Leith Ross Re: VBA... 07-23-2015, 03:37 PM
  1. #1
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    VBA "Scripting.Dictionary" Word Occurences under each category

    I am very new to dictionaries in VBA but I found a macro that does almost exactly what I need it to in a fraction of the time as a formula. I have a list of items that belong to different categories. In one column I have the category, in columns next to it I have the product title, description, and a few bullet points with more descriptions. My goal is to have a macro go through all the items in my sheet and return a list of words in those columns and their occurences in each category.

    I've attached a sample with some dummy data. Dummy_Data.xlsx

    Below is the code that I found at this page.

    Sub HTH() 
        Dim vArray As Variant 
        Dim lLoop As Long 
        Dim rCell As Range 
         
        With CreateObject("Scripting.Dictionary") 
            For Each rCell In Range("A1", Cells(Rows.Count, "A").End(xlUp)) 
                vArray = Split(rCell.Value, " ") 
                For lLoop = LBound(vArray) To UBound(vArray) 
                    If Not .exists(vArray(lLoop)) Then 
                        .Add vArray(lLoop), 1 
                    Else 
                        .Item(vArray(lLoop)) = .Item(vArray(lLoop)) + 1 
                    End If 
                Next lLoop 
            Next rCell 
            Range("B1").Resize(.Count).Value = Application.Transpose(.keys) 
            Range("C1").Resize(.Count).Value = Application.Transpose(.items) 
        End With 
    End Sub
    This code gives me the count of each word's occurence. The shortcoming here is that it includes special characters. For example: Ther could be the word "great" and "great," and each one would have their own count. My goal is to eliminate the special characters before counting. Also, I would like it to give me the word and the count within each category.

    This next request is only optional but would be great. I would also like to get a list of two word combinations and their counts. For example if a phrase contained "big dog" then it would be counted. If a phrase contained "Big bad dog" then "Big Bad" and "Bad Dog" would be counted.

    Also, I would like it so it isn't case sensitive when counting.

    Any help on this would be greatly appreciated.
    Last edited by manofcheese; 07-23-2015 at 01:37 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 09-10-2014, 02:12 PM
  2. How to make a Pivot Table "Top 10" include an "other" category.
    By Melvinrobb in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 09-09-2014, 05:15 AM
  3. [SOLVED] CreateObject("scripting.dictionary") Add Item Problem---->Empty Cells
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2014, 05:04 PM
  4. Replies: 1
    Last Post: 01-15-2014, 08:53 AM
  5. [SOLVED] How to understand and use CreateObject("Scripting.Dictionary")
    By Darthzo in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-03-2013, 07:21 PM
  6. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  7. Replies: 7
    Last Post: 05-13-2006, 05:02 PM

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