Excel中逗号分隔列的唯一值

时间:2016-04-14 14:15:56

标签: excel excel-2010 distinct

给定一个看起来像这样的表,一列充满逗号分隔值:

Col 1

"a,b,c"
"c,b,a"
"a,b"
"b,a"
"b,a"
"x,y,z"

我希望能够列出该列数据中的所有唯一值。我应该看到a,b,c,x,y,z

有没有办法在Excel 2010中执行此操作?

1 个答案:

答案 0 :(得分:1)

考虑:

Sub Uniqquuee()
    Dim N As Long, i As Long, C As Collection
    Dim dq As String

    dq = Chr(34)
    Set C = New Collection
    N = Cells(Rows.Count, "A").End(xlUp).Row

    For i = 1 To N
        ary = Split(Replace(Cells(i, 1).Text, dq, ""), ",")
        For Each a In ary
            On Error Resume Next
                C.Add a, CStr(a)
            On Error GoTo 0
        Next a
    Next i

    For i = 1 To C.Count
        st = st & "," & C.Item(i)
    Next i
    MsgBox Mid(st, 2)
End Sub

enter image description here