+ -
当前位置:首页 → 问答吧 → sheet1A列和B列与sheet2A列和B列作对比

sheet1A列和B列与sheet2A列和B列作对比

时间:2011-08-02

来源:互联网

sheet1中的A列和B列中的数与sheet2中的A列和B列中的数作对比,
如果sheet1中有,而sheet2没有,那么sheet1中此数的所在行就删除,
如果sheet2中有,那么sheet和sheet2中这两个数所在行背景色改为黄色

谢谢各位高手!!

附件

304.zip(11.06 KB)

2011-8-2 14:33, 下载次数: 3

附表

作者: jjip123   发布时间: 2011-08-02

欢迎新会员jjip123
请测试:
Sub Macro1()
    Dim d1 As Object, d2 As Object, arr1, arr2, s$
    Dim i&, t, sh1 As Worksheet, sh2 As Worksheet
    Set sh1 = Sheets("Sheet1")
    Set sh2 = Sheets("Sheet2")
    sh1.Cells.Interior.ColorIndex = xlNone
    sh2.Cells.Interior.ColorIndex = xlNone
    Set d1 = CreateObject("scripting.dictionary")
    Set d2 = CreateObject("scripting.dictionary")
    arr1 = sh1.[a1].CurrentRegion
    arr2 = sh2.[a1].CurrentRegion
    For i = 3 To UBound(arr1)
        d1(arr1(i, 1) & Chr(9) & arr1(i, 2)) = ""
    Next
    For i = 3 To UBound(arr2)
        d2(arr2(i, 1) & Chr(9) & arr2(i, 2)) = ""
    Next
    For i = 3 To UBound(arr2)
        s = arr2(i, 1) & Chr(9) & arr2(i, 2)
        If d1.Exists(s) And d2.Exists(s) Then
            sh2.Rows(i).Interior.ColorIndex = 6
            d1.Remove (s)
        End If
    Next
    t = d1.items
    With sh1
        For i = UBound(arr1) To 3 Step -1
            s = arr1(i, 1) & Chr(9) & arr1(i, 2)
            If d1.Exists(s) Then .Rows(i).Delete Else .Rows(i).Interior.ColorIndex = 6
        Next
    End With
End Sub

作者: zhaogang1960   发布时间: 2011-08-02

请看附件
304.rar (13.71 KB)
304.rar (13.71 KB)
下载次数: 0
2011-8-2 23:47

作者: zhaogang1960   发布时间: 2011-08-02