excel vba 怎样找出两列不重复的数字?

如上图表格,怎样用vba比较A列与B列内容,同时找出A列与B列没有重复的数字,并按顺序排列在D列展示,求大神解答~

Sub Sfind()
    Dim rng As range, srng As range
    Dim dic As Variant, key As Variant
    Dim i As Integer
    With Sheets("Sheet2") '这里选择表格
        Set srng = .[a1:c5] '这里选择要统计重复的区域
        Set dic = CreateObject("Scripting.Dictionary")
        For Each rng In srng
            If Not IsEmpty(rng.Value) Then
                If Not dic.Exists(rng.Value) Then dic.Add rng.Value, 1
            End If
        Next rng
        key = dic.keys
        .[d2].Resize(UBound(key), 1) = Application.Transpose(key)
        '[d2] 这里是放结果的区域
        Set srng = Nothing
        Set dic = Nothing
    End With
End Sub

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-04-16

以下代码可以做到

Sub 判断不重复数值()

Dim a, b
a = Application.WorksheetFunction.CountA(Columns(1))
b = Application.WorksheetFunction.CountA(Columns(2))

Dim ra, rb, rd
rd = 2

For ra = 2 To a
If Application.WorksheetFunction.CountIf(Columns(2), Cells(ra, 1)) = 0 Then
Cells(rd, 4) = Cells(ra, 1)
rd = rd + 1
End If
Next ra

For rb = 2 To b
If Application.WorksheetFunction.CountIf(Columns(1), Cells(rb, 2)) = 0 Then
Cells(rd, 4) = Cells(rb, 2)
rd = rd + 1
End If
Next rb

End Sub

已上传附件

本回答被提问者和网友采纳
第2个回答  2015-04-16
VBA不懂,用公式整行不?
相似回答