|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
首先感谢三坛老窖的帮助,解决了核算的问题,
在实际应用中,发现核对比较困难,需要增加对应成品信息。
如需求材料1为10KG,他对应的产品为产品1计5件,产品2计3件等,这样的话,可以方便核对了。
请高手协助修改,原代码我都看不懂,看着看着就晕了。
另外,如果有子件规格,如何加进去,使在材料需求中也显示出来,目前使用的方法为通过VLOOKUP找的。
原代码如下,详见附件
Const MAXTAB As Byte = 10
Dim dicBOM, dicM
Private Sub CommandButton1_Click()
Dim i&, arr
i = Worksheets("BOM").Range("A" & Cells.Rows.Count).End(xlUp).Row
arr = Worksheets("BOM").Range("A2:C" & i)
Set dicBOM = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(arr)
dicBOM(arr(i, 1)) = dicBOM(arr(i, 1)) & arr(i, 2) & "," & arr(i, 3) & "/"
Next
i = Range("A" & Cells.Rows.Count).End(xlUp).Row
arr = Range("A2:B" & i)
Set dicM = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(arr)
BOM arr(i, 1), arr(i, 2), 0
Next i
i = dicM.Count
With Worksheets("需求")
.Range("A1").CurrentRegion.Offset(1).ClearContents
.Range("A2").Resize(i) = Application.Transpose(dicM.keys)
.Range("B2").Resize(i) = Application.Transpose(dicM.items)
.Select
End With
Set dicBOM = Nothing
Set dicM = Nothing
End Sub
Private Sub BOM(ByVal Pid As String, ByVal N As Double, ByVal iTab As Long)
Dim i&, temp1, temp2
If iTab >= MAXTAB Then Exit Sub
If dicBOM.exists(Pid) Then
temp1 = Split(dicBOM(Pid), "/")
For i = 0 To UBound(temp1) - 1
temp2 = Split(temp1(i), ",")
BOM temp2(0), N * temp2(1), iTab + 1
Next
Else
dicM(Pid) = dicM(Pid) + N
End If
End Sub |
|