Excel - All unique words in a range

后端 未结 2 1348
遇见更好的自我
遇见更好的自我 2021-01-14 15:18

Perhaps I\'m trying to do too much, but I have a column filled with text. Each cell has an arbitrary number of words, so for example:

     |         A                


        
2条回答
  •  生来不讨喜
    2021-01-14 15:40

    Give this small macro a try:

    Sub dural()
        Dim N As Long, U As Long, L As Long
        N = Cells(Rows.Count, "A").End(xlUp).Row
        Dim st As String
        For I = 1 To N
            st = st & " " & Cells(I, 1)
        Next I
        st = Application.WorksheetFunction.Trim(st)
        ary = Split(st, " ")
        U = UBound(ary)
        L = LBound(ary)
        Dim c As Collection
        Set c = New Collection
        On Error Resume Next
        For I = L To U
            c.Add ary(I), CStr(ary(I))
        Next I
        For I = 1 To c.Count
            Cells(I, 2).Value = c.Item(I)
        Next I
    End Sub
    

提交回复
热议问题