如何从两列Excel VBA中提取唯一值

时间:2015-08-17 13:43:17

标签: excel vba excel-vba

我需要在列(E)中显示列(A)和列(C)之间的唯一值

1 个答案:

答案 0 :(得分:1)

此代码:

Sub GetUniques()
    Dim Na As Long, Nc As Long, Ne As Long
    Dim i As Long
    Na = Cells(Rows.Count, "A").End(xlUp).Row
    Nc = Cells(Rows.Count, "C").End(xlUp).Row
    Ne = 1

    For i = 1 To Na
        Cells(Ne, "E").Value = Cells(i, "A").Value
        Ne = Ne + 1
    Next i
    For i = 1 To Na
        Cells(Ne, "E").Value = Cells(i, "C").Value
        Ne = Ne + 1
    Next i

    Range("E:E").RemoveDuplicates Columns:=1, Header:=xlNo
End Sub

会产生这种结果:

enter image description here