Option Explicit
Sub TEST() '↑
Dim Arr, Brr, Crr, V$, Y, R&, i&, S&, T1$, T3$
Set Y = CreateObject("Scripting.Dictionary")
Brr = Range([交期!C2], [交期!A65536].End(xlUp))
For i = 1 To UBound(Brr): Y(Brr(i, 1)) = Y(Brr(i, 1)) & "/" & i: Next
Crr = Range([WIP!C2], [WIP!A65536].End(xlUp))
ReDim Arr(1 To UBound(Crr), 1 To 1)
For i = 1 To UBound(Crr)
T1 = Crr(i, 1): T3 = Crr(i, 3)
If Y(T1) = "" Then Arr(i, 1) = "無訂單": GoTo i01
i00: S = Y(T1 & "|餘量")
If S <= 0 Then
V = Mid(Y(T1), InStr(Y(T1), "/") + 1) & "/": R = Val(V)
If R = 0 Then Arr(i, 1) = "無續單": GoTo i01
Y(T1) = V: Y(T1 & "|餘量") = Brr(R, 3) + S
If Y(T1 & "|餘量") <= 0 Then GoTo i00
Y(T1 & "|交期") = Brr(R, 2)
End If
Arr(i, 1) = Y(T1 & "|交期")
Y(T1 & "|餘量") = Y(T1 & "|餘量") - Crr(i, 3)
i01: Next
[WIP!D2].Resize(UBound(Arr)) = Arr
Set Y = Nothing: Erase Arr, Brr, Crr
End Sub