Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 05-29-2014, 07:30 PM
whatsup whatsup is offline Counting Keywords and Phrases Windows 7 64bit Counting Keywords and Phrases Office 2010 32bit
Competent Performer
 
Join Date: May 2014
Posts: 137
whatsup will become famous soon enough
Default

Hi @all

Though it's possible to split phrases by excel functions you will spend a lot of time (and space on your worksheet) to get everything done, whereas a couple of lines of vba-code do the trick - and it's written in few minutes. Just as idea:
Code:
 
Sub Do_It()
Dim arr As Variant
Dim arrSplit As Variant
Dim vntItem As Variant
Dim objphrase As Object
Dim objkeys As Object

Dim lngItem As Long, lngkeys As Long

Set objphrase = CreateObject("scripting.dictionary")
Set objkeys = CreateObject("scripting.dictionary")

'Get Data of Column C
With ActiveSheet
    arr = .Range("C2:C" & .Cells(Rows.Count, 3).End(xlUp).Row).Value
End With

For lngItem = 1 To UBound(arr, 1)
    'just in case...
    arr(lngItem, 1) = Trim(CStr(arr(lngItem, 1)))
    If Not arr(lngItem, 1) = "" Then
        'makes things easier ...
        arr(lngItem, 1) = " " & arr(lngItem, 1) & " "
        'Collect and count phrases
        If objphrase.Exists(arr(lngItem, 1)) Then
            objphrase(arr(lngItem, 1)) = objphrase(arr(lngItem, 1)) + 1
        Else
            objphrase(arr(lngItem, 1)) = 1
        End If
        'extract keys
        arrSplit = Split(arr(lngItem, 1), " ")
        'Collect and count keys
        For lngkeys = 1 To UBound(arrSplit) - 1
            If objkeys.Exists(arrSplit(lngkeys)) Then
                objkeys(arrSplit(lngkeys)) = objkeys(arrSplit(lngkeys)) + 1
            Else
                objkeys(arrSplit(lngkeys)) = 1
            End If
        Next lngkeys
    End If
Next lngItem

 'Report
With ActiveSheet
    If objkeys.Count > 0 Then
        lngItem = 0
        ReDim arr(1 To objkeys.Count, 1 To 2)
        For Each vntItem In objkeys
            lngItem = lngItem + 1
            arr(lngItem, 1) = vntItem
            arr(lngItem, 2) = objkeys(vntItem)
        Next vntItem
        .Cells(2, 5).Resize(UBound(arr, 1), 2).Value = arr
    End If
    If objphrase.Count > 0 Then
        lngItem = 0
        ReDim arr(1 To objphrase.Count, 1 To 2)
        For Each vntItem In objphrase
            lngItem = lngItem + 1
            arr(lngItem, 1) = vntItem
            arr(lngItem, 2) = objphrase(vntItem)
        Next vntItem
        .Cells(2, 7).Resize(UBound(arr, 1), 2).Value = arr
    End If
End With

 'Clean up
Set objkeys = Nothing
Set objphrase = Nothing

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I find Repeating Words/Phrases? CCD2016 PowerPoint 0 12-01-2013 09:37 PM
Counting Keywords and Phrases Identify certain text and move all phrases containing it down a line Chayes Word VBA 2 11-26-2013 01:16 PM
Counting Keywords and Phrases Selecting text between two key phrases Chayes Word VBA 6 06-24-2012 06:54 PM
Updating Hyperlinks with svn keywords ehsansad Word 0 04-28-2011 03:14 AM
Counting Keywords and Phrases Automatically Hyperlink phrases TinaIgnatiev Word 1 12-22-2010 01:42 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft