|
Sub 数据比对()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("sheet1")
r = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("b3:e" & r)
rs = .Cells(Rows.Count, 12).End(xlUp).Row
br = .Range("l3:p" & rs)
ReDim arr(1 To UBound(ar) + UBound(br), 1 To 4)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
t = d(Trim(ar(i, 1)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 1))) = k
t = k
arr(k, 1) = ar(i, 1)
End If
arr(t, 3) = arr(t, 3) + ar(i, 4)
End If
Next i
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
t = d(Trim(br(i, 1)))
If t = "" Then
k = k + 1
d(Trim(br(i, 1))) = k
t = k
arr(k, 1) = br(i, 1)
End If
arr(t, 2) = arr(t, 2) + br(i, 5)
arr(t, 4) = arr(t, 2) - arr(t, 3)
End If
Next i
ws = .Cells(Rows.Count, 8).End(xlUp).Row
If ws >= 4 Then .Range("h3:k" & ws) = Empty
.[h4].Resize(k, 4) = arr
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|