如何从两列Excel VBA中提取唯一值 [英] How to extract unique values from two columns Excel VBA

查看:345
本文介绍了如何从两列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:

这篇关于如何从两列Excel VBA中提取唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆