try this:
Sub zz()
Dim ar, d As Object, x$
Set d = CreateObject("scripting.dictionary")
For Each s In Sheets
If InStr(1, s.Name, "Data_", 1) Then
ar = s.[b1048576].End(3).CurrentRegion.Value
For i = 2 To UBound(ar)
d(ar(i, 1)) = d(ar(i, 1)) + ar(i, 2)
Next
End If
Next
ar = Sheets("D_ALL").UsedRange.Value
For i = 2 To UBound(ar)
t = d(ar(i, 1)) - ar(i, 2)
If t Then
d(ar(i, 1)) = t
Else
d.Remove (ar(i, 1))
End If
Next
If d.Count Then
k = d.keys: t = d.items
For i = 0 To UBound(t)
If t(i) > 0 Then
k(i) = k(i) & " +" & t(i)
Else
k(i) = k(i) & " " & t(i)
End If
Next
End If
MsgBox Join(k, Chr(10))
End Sub作者: Kubi 時間: 2017-9-27 21:23