|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 数据比对()
Dim ar As Variant
Dim d As Object
Dim rn As Range
Set d = CreateObject("scripting.dictionary")
With Sheets("sheet2")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "sheet2为空!": End
ar = .Range("a1:d" & r)
End With
For i = 2 To UBound(ar)
zf = ""
If ar(i, 1) <> "" Then
For j = 1 To 4
If j = 1 Then
zf = ar(i, j)
Else
zf = zf & "|" & ar(i, j)
End If
Next j
d(zf) = i
End If
Next i
With Sheets("sheet1")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs < 2 Then MsgBox "sheet1为空!": End
br = .Range("a1:d" & rs)
.Range("a1:d" & rs).Interior.ColorIndex = 0
For i = 2 To UBound(br)
zf = ""
If br(i, 1) <> "" Then
For j = 1 To 4
If j = 1 Then
zf = br(i, j)
Else
zf = zf & "|" & br(i, j)
End If
Next j
xh = d(zf)
If xh = "" Then
If rn Is Nothing Then
Set rn = .Range("a" & i).Resize(1, 4)
Else
Set rn = Union(rn, .Range("a" & i).Resize(1, 4))
End If
End If
End If
Next i
If Not rn Is Nothing Then rn.Interior.ColorIndex = 6
End With
MsgBox "ok!"
End Sub
|
|