EXCEL VBA两列判断重复

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

你可能感兴趣的:(excelVBA专栏,excel)