簡體   English   中英

如何從兩列Excel VBA中提取唯一值

[英]How to extract unique values from two columns Excel VBA

我需要獲取列(A)和列(C)之間的唯一值才能在列(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

將產生這種類型的結果:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM