|
- Sub tt()
- Dim Bomrr, Brr, Lr
- Dim BQrr, Planrr, RQrr
- Dim D, T
- Lr = Sheet1.Range("a65536").End(3).Row
- Brr = Sheet1.Range("a4:h" & Lr)
- ReDim Bomrr(1 To UBound(Brr), 1 To 3)
- For i = 1 To UBound(Brr)
- Bomrr(i, 1) = Brr(i, 1)
- Bomrr(i, 2) = Brr(i, 5)
- Bomrr(i, 3) = Brr(i, 8)
- Next i
- Set D = CreateObject("Scripting.Dictionary")
- For i = 1 To UBound(Bomrr)
- If Not D.Exists(Bomrr(i, 1)) Then
- D(Bomrr(i, 1)) = D(Bomrr(i, 1))
- End If
- Next i
- T = D.keys
- Lr = Sheet2.Range("a65536").End(3).Row
- Planrr = Sheet2.Range("a3:ai" & Lr)
- Lr = Sheet3.Range("a65536").End(3).Row
- RQrr = Sheet3.Range("a3:ai" & Lr)
- ReDim BQrr(1 To UBound(RQrr) + 1, 1 To D.Count)
- k = 1
- For Each temp In T
- BQrr(1, k) = temp
- D(temp) = D(temp) + k
- k = k + 1
- Next
- For k = 1 To D.Count
- For i = 1 To UBound(RQrr) '如果bom单中物料项超过200项,下列遍历需要修改,避免时间过长
- For j = 1 To UBound(Bomrr)
- If BQrr(1, k) = Bomrr(j, 1) And RQrr(i, 3) = Bomrr(j, 2) Then
- BQrr(i + 1, k) = Bomrr(j, 3)
- End If
- Next j
- Next i
- Next k
- For k = 1 To UBound(Planrr)
- For j = 1 To UBound(RQrr)
- 'If Not BQrr(j + 1, D(Planrr(k, 1))) = "" Then
- For i = 5 To UBound(Planrr, 2)
- RQrr(j, i) = RQrr(j, i) + BQrr(j + 1, D(Planrr(k, 1))) * Planrr(k, i)
- Next i
- 'End If
- Next j
- Sheet6.Range("e3").Resize(UBound(RQrr), UBound(RQrr, 2)) = RQrr
- Next k
- Sheet3.Range("a3").Resize(UBound(RQrr), UBound(RQrr, 2)) = RQrr
- End Sub
复制代码 |
|