Sub yy()
Dim rng, d As Object, i&, c As Range, x As Date, y!
Set d = CreateObject("Scripting.Dictionary")
With Sheet1
rng = .Range(.[a3], .[d65536].End(3))
End With
For i = 1 To UBound(rng)
If Not d.exists(rng(i, 2)) Then
d(rng(i, 2)) = Array(rng(i, 1), rng(i, 4))
Else
x = Format(IIf(rng(i, 1) > d(rng(i, 2))(0), rng(i, 1), d(rng(i, 2))(0)), "yyyy/m/d")
y = d(rng(i, 2))(1) + rng(i, 4)
d(rng(i, 2)) = Array(x, y)
End If
Next i
With Sheet2
For Each c In .Range(.[a3], .[a65536].End(3))
c(1, 3).Resize(, 2) = d(c & "")
Next
End With
End Sub |