Creating list of unique words from multiple cells

marknorton

New Member
Joined
Aug 7, 2008
Messages
6
Hi

Please help. Not sure if this is possible or not!

I have a list of similar phrases in column A.

For example:

tomato soup
tomato soup heinz
soup heinz
heinz soup
tomato soup heinz 57

Is there a way of Excel pulling a list of unique keywords from all those cells?

So it would end up with a column containing:

tomato
soup
heinz
57
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi, marknoton
Try this
Code:
Sub extractWord()
    Dim strArray() As String
    Dim d As Object, e
    Dim i As Long
    Dim rr As Long
    Dim r As Range
    Dim Rng As Range

    Set d = CreateObject("scripting.dictionary")
    rr = Range("A" & Rows.count).End(xlUp).row
    Set Rng = Range("A1:A" & rr)
      
    For Each r In Rng
     strArray = Split(r, " ")
        For i = LBound(strArray) To UBound(strArray)
            If Not d.Exists(strArray(i)) Then d.Add strArray(i), 1
        Next
    Next

    i = 1
    For Each e In d
    Cells(i, 3) = e
    i = i + 1
    Next
        
End Sub
 
Upvote 0
.. similar idea, but a bit more compact:
Rich (BB code):
Sub MakeList()
  Dim d As Object
  Dim r As Range
  Dim Itm As Variant
  
  Set d = CreateObject("Scripting.Dictionary")
  d.compareMode = 1
  For Each r In Range("A1", Range("A" & Rows.Count).End(xlUp))
    For Each Itm In Split(r.Value)
      d(Itm) = 1
    Next Itm
  Next r
  Range("C1").Resize(d.Count).Value = Application.Transpose(Array(d.keys))
End Sub
 
Upvote 0
Nice code Peter!
I learn something from it. Thanks.
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,469
Latest member
Kingwi11y

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