本帖最后由 蓝桥玄霜 于 2013-5-31 21:08 编辑
当看到BOM表格的时候,我们大都会觉得眼花缭乱,被那么多的层级搞糊涂了,我不知道他们在实际工作中是怎么计算的,如果手工计算的话,真是需要足够的耐心和毅力。 最近看到有会员来求助,经过一段时间的研究,我找到了一个计算方法,称之为蓝桥方法。希望能够使被这种计算困扰的人们解放出来。 该方法的思路比较简单清晰: 1, 先用字典求得各层级材料所在行的行数;这是容易做到的; 2, 通过下一层级与上一层级的逐级比较,获得各层级材料的上一层级所在的行位置,并且放入另一个字典; 3, 通过不同的计算方法计算成本和工时的汇总。
期待大家提供实例来测试,以便完善计算方法。
- Public Arr, d, d1, k, t
- Sub lqxs_cbgs0528()
- '适用于加子件本身数量的工时算法
- '适用于不加子件本身数量的成本算法
- 'by:蓝桥玄霜 2013-5-28
- Dim i&, Brr, k2, t2, j&, aa, a, tt2, zjj
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- 'Sheet5.Activate
- [i2:l50000] = ""
- Arr = [a1].CurrentRegion
- ReDim Brr(1 To UBound(Arr), 1 To UBound(Arr, 2) - 3)
- For i = 2 To UBound(Arr)
- d(Arr(i, 1)) = d(Arr(i, 1)) & i & ","
- Next
- k = d.keys: t = d.items
- For i = 0 To UBound(k)
- If i = 0 Then
- Call yy0(t(i), i)
- Else
- Call yy(t(i), i)
- End If
- Next
- k2 = d1.keys: t2 = d1.items
- For ii = 4 To UBound(Arr, 2)
- For i = UBound(k2) To 1 Step -1
- tt2 = Left(t2(i), Len(t2(i)) - 1)
- If InStr(tt2, "|") Then
- aa = Split(tt2, "|")
- For j = 0 To UBound(aa)
- a = Split(aa(j), ",")
- If ii <> 4 Then '计算工时
- If Arr(a(0), ii) <> 0 Then
- zjj = Arr(a(0), 3) * Arr(a(0), ii)
- Brr(a(0), ii - 3) = Brr(a(0), ii - 3) + zjj
- Brr(a(2), ii - 3) = Brr(a(2), ii - 3) + Arr(a(2), 3) * Brr(a(0), ii - 3)
- Else
- Brr(a(2), ii - 3) = Brr(a(2), ii - 3) + Arr(a(2), 3) * Brr(a(0), ii - 3)
- End If
- Else '计算成本
- If Brr(a(0), ii - 3) = 0 Then
- zjj = Arr(a(0), 3) * Arr(a(0), ii)
- Else
- zjj = Brr(a(0), ii - 3)
- End If
- Brr(a(2), ii - 3) = Brr(a(2), ii - 3) + zjj * Arr(a(2), 3)
- End If
- Next
- End If
- Next
- Brr(1, ii - 3) = Cells(1, ii + 5).Value
- Next
- Cells(1, 9).Resize(UBound(Arr), 4) = Brr
- End Sub
- Public Sub yy(tt, c)
- 'by:蓝桥玄霜 2013-5-28
- Dim k1, t1, t2, j&, aa, sj, gs, i&, bb
- t1 = Left(t(c - 1), Len(t(c - 1)) - 1)
- t2 = Left(tt, Len(tt) - 1)
- If InStr(t2, ",") Then
- bb = Split(t2, ",")
- For j = 0 To UBound(bb)
- If InStr(t1, ",") Then
- aa = Split(t1, ",")
- For i = UBound(aa) To 0 Step -1
- If Val(bb(j)) > Val(aa(i)) Then
- sj = aa(i): gs = Arr(bb(j), 3)
- d1(k(c)) = d1(k(c)) & bb(j) & "," & gs & "," & sj & "|"
- Exit For
- End If
- Next
- Else
- sj = t1: gs = Arr(bb(j), 3)
- d1(k(c)) = d1(k(c)) & bb(j) & "," & gs & "," & sj & "|"
- End If
- Next
- Else
- gs = Arr(t2, 3): sj = t2 - 1
- d1(k(c)) = d1(k(c)) & t2 & "," & gs & "," & sj & "|"
- End If
- End Sub
- Public Sub yy0(tt, c)
- 'by:蓝桥玄霜 2013-5-28
- Dim t1, bb, j&, sj, gs
- t1 = Left(tt, Len(tt) - 1)
- If InStr(t1, ",") Then
- bb = Split(t1, ",")
- For j = 0 To UBound(bb)
- sj = bb(j): gs = Arr(bb(j), 3)
- d1(k(c)) = d1(k(c)) & bb(j) & "," & gs & "," & sj & "|"
- Next
- Else
- gs = Arr(t1, 3): sj = t1
- d1(k(c)) = d1(k(c)) & t1 & "," & gs & "," & sj & "|"
- End If
- End Sub
复制代码
该贴已经同步到 蓝桥玄霜的微博 |