|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
只是一种方式,结果不一定正确
思路是论坛的,不过很好用!
代码太长,给出主要函数
- Private Function Get_data(PN, QTY, DATEX)
- Rem 编码,用量
- Rem 在BOM表中找
- Dim DOU2 As Double
- Dim A As Long
-
- For A = 0 To UBound(Arr_BOM, 1)
- Rem 存在此编码
- If Arr_BOM(A, 0) = PN Then
- If Dic_temp.exists(Arr_BOM(A, 2)) Then
- Rem 如果词典中存在子件,就进行递归
- Get_data = Get_data(Arr_BOM(A, 2), Deduct_Stock(Arr_BOM(A, 2), Arr_BOM(A, 3), Arr_BOM(A, 4), QTY, DATEX), DATEX)
- Else
- Rem 如果已经是最底层,则操作公用数组
- Rem 加一个一行
- If IsNull(Arr_BOM(A, 3)) = True Then Arr_BOM(A, 3) = " "
- DOU2 = Deduct_Stock(Arr_BOM(A, 2), Arr_BOM(A, 3), Arr_BOM(A, 4), QTY, DATEX)
-
- ReDim Preserve Arr_结果(0 To UBound(Arr_结果, 1), 0 To UBound(Arr_结果, 2) + 1)
- Arr_结果(0, UBound(Arr_结果, 2)) = Arr_BOM(A, 2)
- Arr_结果(1, UBound(Arr_结果, 2)) = Arr_BOM(A, 3)
- Arr_结果(2, UBound(Arr_结果, 2)) = DATEX
- Arr_结果(3, UBound(Arr_结果, 2)) = DOU2
- Arr_结果(4, UBound(Arr_结果, 2)) = "BOM"
- End If
- End If
- Next A
-
-
- End Function
- Private Function Deduct_Stock(PN, NAME, Usage, Demand_Qty, DATEX)
- Rem 检查库存,将需求从库存中扣除
- Dim DOU1, DOU2 As Double
- Dim A As Long
- Dim DATE1 As Date
- DOU1 = Usage * Demand_Qty
- DOU2 = 0
- If IsNull(Usage) = True Then Usage = 0
- If IsNull(NAME) = True Then NAME = " "
-
- For A = LBound(Arr_库存, 1) + 1 To UBound(Arr_库存, 1)
- Rem 找到此父件,日期
- If Arr_库存(A, 2) = PN Then
- If Arr_库存(A, 4) >= DOU1 Then
- Rem 如果库存大于所需,库存中扣减掉此次用量
- DOU2 = Usage * Demand_Qty
- Else
- Rem 如果库存小于所需,库存=0,扣减库存后数量向BOM表找
- DOU2 = Arr_库存(A, 4)
- End If
- Arr_库存(A, 4) = Arr_库存(A, 4) - DOU2
- If DOU2 > 0 And DOU1 > 0 Then
- ReDim Preserve Arr_结果(0 To UBound(Arr_结果, 1), 0 To UBound(Arr_结果, 2) + 1)
- Arr_结果(0, UBound(Arr_结果, 2)) = PN
- Arr_结果(1, UBound(Arr_结果, 2)) = NAME
- Arr_结果(2, UBound(Arr_结果, 2)) = DATEX
- Arr_结果(3, UBound(Arr_结果, 2)) = DOU2
- Arr_结果(4, UBound(Arr_结果, 2)) = "库存"
- DOU1 = DOU1 - DOU2
- End If
- End If
- Next A
-
- Rem 如果库存无数据,则全部向BOM表找
- Deduct_Stock = DOU1 '//Usage * Demand_Qty - DOU2
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|