|
- Sub tj()
- Dim dic As Object
- Set dic = CreateObject("scripting.dictionary")
- arr = Sheet4.Range("A1:I" & Sheet4.Cells(Rows.Count, 2).End(xlUp).Row) '订单明细
- ReDim brr(1 To UBound(arr), 1 To 8)
- For i = 4 To UBound(arr)
- Key = arr(i, 4) & "|" & arr(i, 5) & "|" & arr(i, 6) & "|" & arr(i, 7) '名称+规格+单位+门类
- If Not dic.Exists(Key) Then
- k = k + 1
- dic(Key) = k
- brr(k, 1) = k
- brr(k, 2) = arr(i, 4)
- brr(k, 3) = arr(i, 5)
- brr(k, 4) = arr(i, 6)
- brr(k, 5) = arr(i, 7)
- brr(k, 6) = arr(i, 8) '订单数量
- Else
- s = dic(Key)
- brr(s, 6) = brr(s, 6) + arr(i, 8)
- End If
- Next
- arr = Sheet6.Range("A1:J" & Sheet6.Cells(Rows.Count, 1).End(xlUp).Row) '月报表
- For i = 4 To UBound(arr)
- Key = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(i, 3) & "|" & arr(i, 4) '名称+规格+单位+门类
- If Not dic.Exists(Key) Then
- k = k + 1
- dic(Key) = k
- brr(k, 1) = k
- brr(k, 2) = arr(i, 1)
- brr(k, 3) = arr(i, 2)
- brr(k, 4) = arr(i, 3)
- brr(k, 5) = arr(i, 4)
- brr(k, 7) = arr(i, 6) '入库总量
- brr(k, 8) = brr(k, 6) - brr(k, 7) '需产数量
- If brr(k, 8) < 0 Then brr(k, 8) = 0
- Else
- s = dic(Key)
- brr(s, 7) = brr(s, 7) + arr(i, 6) '入库总量累加
- brr(s, 8) = brr(s, 6) - brr(s, 7) '需产数量
- If brr(s, 8) < 0 Then brr(s, 8) = 0
- End If
- Next
- Sheet11.Range("A4:i" & Rows.Count).ClearContents '清空结果输出区
- Sheet11.Range("a4").Resize(k, 8) = brr
- End Sub
复制代码
|
|