Option Explicit
Sub zz()
Dim arr, brr, i, dic, n
Set dic = CreateObject("scripting.dictionary")
arr = [a1].CurrentRegion
For i = 1 To UBound(arr, 1)
If dic.exists(arr(i, 1)) Then
arr(dic(arr(i, 1)), 2) = arr(dic(arr(i, 1)), 2) + arr(i, 2)
Else
n = n + 1: arr(n, 1) = arr(i, 1): arr(n, 2) = arr(i, 2)
dic(arr(i, 1)) = n
End If
Next
brr = [e1].CurrentRegion
If IsArray(brr) Then '
For i = 1 To UBound(brr, 1)
If Not dic.exists(brr(i, 1)) Then
n = n + 1: arr(n, 1) = brr(i, 1)
arr(n, 2) = IIf(Len(brr(i, 2)) = 0, 0, brr(i, 2))
End If
Next
End If
With [e1]
.Resize(Rows.Count, 2).ClearContents
.Resize(n, 2) = arr
End With
End Sub |