|
Sub 数据比对()
Dim ar As Variant, br As Variant
Dim rn As Range
Dim d As Object
Set d = CreateObject("scripting.dictionary")
ar = Sheet2.[a1].CurrentRegion
For i = 1 To UBound(ar)
If ar(i, 4) <> "" Then
d(ar(i, 4)) = i
End If
Next i
With Sheet1
.[a1].CurrentRegion.Interior.ColorIndex = 0
br = .[a1].CurrentRegion
For i = 1 To UBound(br)
If br(i, 4) <> "" Then
If Not d.exists(br(i, 4)) Then
If rn Is Nothing Then
Set rn = .Cells(i, 1).Resize(1, 6)
Else
Set rn = Union(rn, .Cells(i, 1).Resize(1, 6))
End If
Else
xh = d(br(i, 4))
For j = 1 To UBound(br, 2)
If j <= UBound(ar, 2) Then
If br(i, j) <> ar(xh, j) Then
If rn Is Nothing Then
Set rn = .Cells(i, j)
Else
Set rn = Union(rn, .Cells(i, j))
End If
Else
If rn Is Nothing Then
Set rn = .Cells(i, 6)
Else
Set rn = Union(rn, .Cells(i, 6))
End If
End If
End If
Next j
End If
End If
Next i
If Not rn Is Nothing Then rn.Interior.ColorIndex = 6
End With
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|