請測試看看,謝謝
Sub 日期總量查詢()
Dim Arr, xD, T$, Ds As Date, De As Date, i&, j%, n&
Set xD = CreateObject("Scripting.Dictionary")
Ds = [K5]: De = [K6]
Arr = Sheets("訂貨明細表").[a1].CurrentRegion
ReDim Crr(1 To UBound(Arr), 1 To 5)
For i = 2 To UBound(Arr)
If Arr(i, 12) >= Ds And Arr(i, 12) <= De Then
T = Arr(i, 4)
If xD.Exists(T) Then
Crr(xD(T), 3) = Crr(xD(T), 3) + Arr(i, 5)
Else
n = n + 1: xD(T) = n
For j = 3 To 6: Crr(n, j - 2) = Arr(i, j): Next
End If
End If
Next
With Sheets("項目編號")
Arr = .Range("F3").CurrentRegion
For j = 6 To UBound(Arr, 2) Step 10
For i = 4 To UBound(Arr)
T = Arr(i, j): If T = "" Then GoTo 91
xD(T) = Arr(i, j + 9)
91: Next
Next
End With
For i = 1 To n: Crr(i, 5) = xD(Crr(i, 1) & ""): Next
If n > 0 Then
Range("a2:e1000") = ""
Range("a2").Resize(n, 5) = Crr
End If
End Sub作者: BV7BW 時間: 2022-8-22 14:04
庫存部分是否在上提文中修改
Sub 單項目查詢()
'程式資料來源至sanwanq2022-7-29 指導
Dim Arr, xD, T$, Ds As Date, De As Date
Dim Brr(1 To 1, 1 To 4), Crr(), n%, i&, j%
Range("R2:V12").Select
Selection.ClearContents
Range("A2:E1500").Select
Selection.ClearContents
Range("Q2:V300").Select
Selection.ClearContents
'Range("O2:O100").Select
'Selection.ClearContents
Range("K7").Select
Set xD = CreateObject("Scripting.Dictionary")
Ds = [K5]: De = [K6]: T = [K9]
Arr = Sheets("訂貨明細表").[a1].CurrentRegion
ReDim Crr(1 To UBound(Arr), 1 To 5)
For i = 2 To UBound(Arr)
If Arr(i, 4) <> T Then GoTo 99
If Arr(i, 12) >= Ds And Arr(i, 12) <= De Then
If n = 0 Then
n = n + 1: xD(Arr(i, 1) & "") = n
For j = 1 To 4: Brr(1, j) = Arr(i, j + 2): Next
Crr(n, 1) = Arr(i, 1): Crr(n, 2) = Arr(i, 3)
Crr(n, 3) = Arr(i, 4): Crr(n, 4) = Arr(i, 5)
Crr(n, 5) = Arr(i, 6)
Else
If xD.Exists(Arr(i, 1) & "") Then
m = xD(Arr(i, 1) & "")
Crr(m, 4) = Arr(i, 5) + Crr(m, 4)
Else
n = n + 1: xD(Arr(i, 1) & "") = n
Crr(n, 1) = Arr(i, 1): Crr(n, 2) = Arr(i, 3)
Crr(n, 3) = Arr(i, 4): Crr(n, 4) = Arr(i, 5)
Crr(n, 5) = Arr(i, 6)
End If
Brr(1, 3) = Brr(1, 3) + Arr(i, 5)
End If
End If
99: Next
If n > 0 Then
Range("a2:c2") = ""
Range("a2").Resize(1, 4) = Brr
Range("r2:v8") = ""
Range("r2").Resize(n, 5) = Crr
End If
With ActiveSheet
Beep
End With
End Sub作者: samwang 時間: 2022-8-22 14:15