locating #words in cells and counting frequency

curious_dan

New Member
Joined
Mar 14, 2016
Messages
9
I need some help.

I have 1000 rows of data from A1:A100 and in each cell a large amount of text appears in each cell. In amongst the text are hashtags (think of tweets on twitter for example). The hashtags could be located anywhere within the cell. Some will have them, some will not.

At this stage, I don't know what these hashtags are and I'm not looking to pull out specific ones. Instead I'm looking to pull them all out in one long list, with a count of how frequent each one occurs.

Any thoughts?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi,

Happy to see you found your answer.
I was writing code but was too late so I'm still posting it here in case it's of any help :

Code:
Sub test()

    Dim dic As Object
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = vbTextCompare
    
    Dim txt() As String
    
    For Each c In Range("A1:A100")
        
        txt = Split(c.Value, " ")
        For Each w In txt
        
            If InStr(w, "#") = 0 Then GoTo Skip
            
            If dic.Exists(w) Then
                dic(w) = dic(w) + 1
            Else
                dic.Add w, 1
            End If
Skip:
            
        Next w
        
    Next c
    
    For i = 0 To dic.Count - 1
        Range("B" & i + 1).Value = dic.keys()(i)
        Range("C" & i + 1).Value = dic.items()(i)
    Next i
    
    
End Sub
 
Last edited:
Upvote 0
Hi,

Happy to see you found your answer.
I was writing code but was too late so I'm still posting it here in case it's of any help :

Code:
Sub test()

    Dim dic As Object
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = vbTextCompare
    
    Dim txt() As String
    
    For Each c In Range("A1:A100")
        
        txt = Split(c.Value, " ")
        For Each w In txt
        
            If InStr(w, "#") = 0 Then GoTo Skip
            
            If dic.Exists(w) Then
                dic(w) = dic(w) + 1
            Else
                dic.Add w, 1
            End If
Skip:
            
        Next w
        
    Next c
    
    For i = 0 To dic.Count - 1
        Range("B" & i + 1).Value = dic.keys()(i)
        Range("C" & i + 1).Value = dic.items()(i)
    Next i
    
    
End Sub

Great, thanks Louis. :)
 
Upvote 0

Forum statistics

Threads
1,215,521
Messages
6,125,308
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top