EXCEL VBA两列判断重复

发布时间:2024年01月23日

EXCEL VBA两列判断重复

Sub getSame()
    Dim avntData() As Variant, avntList() As Variant
    Dim astrResultsSame() As String, astrResultsDis() As String
    Dim avntTemp
    Dim intCountSame As Integer, intCountDis As Integer
    Dim intTemp As Integer
    avntData() = WorksheetFunction.Transpose(Range("a2:a13").Value)
    avntList() = WorksheetFunction.Transpose(Range("c2:c13").Value)
    For intTemp = 1 To UBound(avntData())
        avntTemp = Filter(avntList(), avntData(intTemp), True)
        If UBound(avntTemp) >= 0 Then
            intCountSame = intCountSame + 1
            ReDim Preserve astrResultsSame(1 To intCountSame)
            astrResultsSame(intCountSame) = avntData(intTemp)
        Else
            intCountDis = intCountDis + 1
            ReDim Preserve astrResultsDis(1 To intCountDis)
            astrResultsDis(intCountDis) = avntData(intTemp)
        End If
    Next intTemp
    Range("F2").Resize(intCountSame, 1) = _
        WorksheetFunction.Transpose(astrResultsSame())
    Range("G2").Resize(intCountDis, 1) = _
        WorksheetFunction.Transpose(astrResultsDis())
End Sub

Sub FilterDemo()
    Dim avntList() As Variant, avntTemp
    avntList = Array("A", "AB", "BC", "AC", "ac", "ab", "a")
    avntTemp = Filter(avntList(), "A", False, vbTextCompare)
    MsgBox Join(avntTemp, ",")
End Sub
Sub ClearRange()
    Range("f2:g13").ClearContents
End Sub
文章来源:https://blog.csdn.net/weixin_43050480/article/details/135758671
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。