|
Sub 分配退货()
Application.ScreenUpdating = False
Dim arr, brr, crr, i%, j%
Set d1 = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")
arr = Range("b2:d" & Cells(Rows.Count, 2).End(xlUp).Row)
brr = Range("f2:g" & Cells(Rows.Count, 7).End(xlUp).Row)
ReDim crr(1 To UBound(arr), 1 To 1)
For i = 1 To UBound(brr)
d1(brr(i, 1)) = brr(i, 2)
Next i
For j = 1 To UBound(arr)
If d1.exists(arr(j, 1)) Then
d2(arr(j, 1)) = d2(arr(j, 1)) + arr(j, 2)
If d2(arr(j, 1)) < d1(arr(j, 1)) Then
crr(j, 1) = arr(j, 2)
Else
crr(j, 1) = arr(j, 2) - (d2(arr(j, 1)) - d1(arr(j, 1)))
End If
If crr(j, 1) < 0 Then crr(j, 1) = 0
End If
Next j
Cells(2, 4).Resize(UBound(arr), 1) = crr
Application.ScreenUpdating = True
End Sub
|
|