|
Sub 欠料表()
Dim d As Object
Dim ar As Variant, br As Variant
Dim arr(), cr()
Set d = CreateObject("scripting.dictionary")
With Sheets(" 原始报表")
r = .Cells(Rows.Count, 2).End(xlUp).Row
ar = .Range("b3:c" & r)
rs = .Cells(Rows.Count, 6).End(xlUp).Row
br = .Range("f3:h" & rs)
ReDim arr(1 To UBound(ar) + UBound(br), 1 To 3)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
m = 0: sl = 0
ReDim cr(1 To UBound(br), 1 To UBound(br, 2))
For s = 2 To UBound(br)
If Trim(br(s, 2)) = Trim(ar(i, 1)) Then
m = m + 1
For j = 1 To UBound(br, 2)
cr(m, j) = br(s, j)
Next j
End If
Next s
For s = 1 To m
n = n + 1
arr(n, 1) = ar(i, 1)
arr(n, 2) = cr(s, 1)
sl = sl + cr(s, 3)
If sl < ar(i, 2) Then
arr(n, 3) = cr(s, 3)
ElseIf sl > ar(i, 2) Then
arr(n, 3) = ar(i, 2) - sl + cr(s, 3)
GoTo 10
End If
Next s
10:
End If
Next i
End With
With Sheets("目标报表")
.[a1].CurrentRegion.Offset(1) = empt
.[a2].Resize(n, UBound(arr, 2)) = arr
End With
MsgBox "ok!"
End Sub
|
|