如何从两列Excel VBA中提取唯一值
问题描述:
我需要获取(A)列和(C)列之间的唯一值,以显示在(E)列中
I need to get the unique values between Column (A) and Column (C) to be shown in Column (E)
答
此代码:
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
将产生这种类型的结果:
will produce this type of result: