DD = [C1]: CC = [A1]
If Not IsDate(DD) Then MsgBox "**請輸入日期!! ": Exit Sub
If CC = "" Then MsgBox "**請輸入[車編]!! ": Exit Sub
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([訂貨明細表!L1], [訂貨明細表!A65536].End(xlUp))
ReDim Brr(1 To UBound(Arr), 1 To 3): Crr = Brr
For i = 2 To UBound(Arr)
If Arr(i, 12) <> DD Or Arr(i, 10) <> CC Then GoTo 101 '比對日期&車編
T = Arr(i, 3): U = xD(T)
If U = 0 Then N = N + 1: U = N: xD(T) = N
Brr(U, 1) = Arr(i, 9) '類別
'Brr(U, 2) = "'" & Arr(i, 11) '項目編號
Brr(U, 2) = Arr(i, 4) '項目名稱
Brr(U, 3) = Brr(U, 3) & IIf(Brr(U, 3) = "", "", " + ") & Arr(i, 5) & "*" & Arr(i, 6)
'---------------------------------
Crr(U, 1) = Arr(i, 9) '類別
'Crr(U, 2) = "'" & Arr(i, 11) '項目編號
Crr(U, 2) = Arr(i, 4) '項目名稱
Crr(U, 3) = Crr(U, 3) & IIf(Crr(U, 3) = "", "", " + ") & Arr(i, 2) & "*" & Arr(i, 5) & Arr(i, 6) '加客戶編
101: Next i
If N = 0 Then MsgBox "**沒有符合指定日期資料!! ": Exit Sub
Application.ScreenUpdating = False
With [客戶配送表!A2].Resize(N, 3)
.Parent.[C1] = DD
.Value = Crr
.Sort Key1:=.Item(1), Order1:=xlAscending, _
Key2:=.Item(2), Order2:=xlAscending, Header:=xlNo
For i = N + 1 To 2 Step -1
If .Cells(i, 1) <> .Cells(i - 1, 1) Then
.Cells(i, 1).Resize(1, 3).Insert Shift:=xlDown
End If
Next i
End With
With [採購需求表!A2].Resize(N, 3)
.Parent.[C1] = DD
.Value = Brr
.Sort Key1:=.Item(1), Order1:=xlAscending, _
Key2:=.Item(2), Order2:=xlAscending, Header:=xlNo
For i = N + 1 To 2 Step -1
If .Cells(i, 1) <> .Cells(i - 1, 1) Then
.Cells(i, 1).Resize(1, 3).Insert Shift:=xlDown
End If
Next i
End With
End Sub
Sub 採購需求客戶配送_綜合()
'程式資料來源至准提部林_出貨作業D版V01_10905
Dim Arr, Brr, Crr, xD, N&, i&, T$, U&, DD
[採購需求表!A2:C500].ClearContents
[客戶配送表!A2:C500].ClearContents
DD = [C1]
If Not IsDate(DD) Then MsgBox "**請輸入日期!! ": Exit Sub
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([訂貨明細表!L1], [訂貨明細表!A65536].End(xlUp))
ReDim Brr(1 To UBound(Arr), 1 To 3): Crr = Brr
For i = 2 To UBound(Arr)
If Arr(i, 12) <> DD Then GoTo 101 '比對日期
T = Arr(i, 3): U = xD(T)
If U = 0 Then N = N + 1: U = N: xD(T) = N
Brr(U, 1) = Arr(i, 9) '類別
'Brr(U, 2) = "'" & Arr(i, 11) '項目編號
Brr(U, 2) = Arr(i, 4) '項目名稱
Brr(U, 3) = Brr(U, 3) & IIf(Brr(U, 3) = "", "", " + ") & Arr(i, 5) & "*" & Arr(i, 6)
'---------------------------------
Crr(U, 1) = Arr(i, 9) '類別
'Crr(U, 2) = "'" & Arr(i, 11) '項目編號
Crr(U, 2) = Arr(i, 4) '項目名稱
Crr(U, 3) = Crr(U, 3) & IIf(Crr(U, 3) = "", "", " + ") & Arr(i, 2) & "*" & Arr(i, 5) & Arr(i, 6) '加客戶編
101: Next i
If N = 0 Then MsgBox "**沒有符合指定日期資料!! ": Exit Sub
Application.ScreenUpdating = False
With [客戶配送表!A2].Resize(N, 3)
.Parent.[C1] = DD
.Value = Crr
.Sort Key1:=.Item(1), Order1:=xlAscending, _
Key2:=.Item(2), Order2:=xlAscending, Header:=xlNo
For i = N + 1 To 2 Step -1
If .Cells(i, 1) <> .Cells(i - 1, 1) Then
.Cells(i, 1).Resize(1, 3).Insert Shift:=xlDown
End If
Next i
End With
With [採購需求表!A2].Resize(N, 3)
.Parent.[C1] = DD
.Value = Brr
.Sort Key1:=.Item(1), Order1:=xlAscending, _
Key2:=.Item(2), Order2:=xlAscending, Header:=xlNo
For i = N + 1 To 2 Step -1
If .Cells(i, 1) <> .Cells(i - 1, 1) Then
.Cells(i, 1).Resize(1, 3).Insert Shift:=xlDown
End If
Next i
End With
End Sub