|
楼主 |
发表于 2022-12-7 11:47
|
显示全部楼层
代码更新,计算更准确!- Private Sub 材料_Click()
- 'Application.ScreenUpdating = False
- Dim ar, i&, cr, dr
- Dim cl%, qh(1000) '层级可自行修改
-
- With Sheet1
- Sheet1.Range(Sheet1.Cells(2, 7), Sheet1.Cells(Sheet1.Range("a" & Rows.Count).End(xlUp).Row, Sheet1.Cells(1, Columns.Count).End(xlToLeft).Column)) = Empty
- ar = .Range("a1").CurrentRegion.Resize(, 7)
- For i = UBound(ar, 1) To 2 Step -1
- If ar(i, 1) = cl - 1 Then
- ar(i, 6) = qh(cl)
- qh(cl) = 0
- End If
- ar(i, 7) = ar(i, 4) * (1 + ar(i, 5)) * ar(i, 6)
- cl = ar(i, 1)
- qh(cl) = qh(cl) + ar(i, 4) * (1 + ar(i, 5)) * ar(i, 6)
- Next
- Sheet1.Range("a1").Resize(UBound(ar, 1), 7) = ar
- ar = .Range("a1").CurrentRegion.Resize(, 8)
- ReDim cr(0 To 1000, 1 To 2) '最近阶半成品提取
- For i = 2 To UBound(ar, 1)
- If ar(i, 1) = 0 Then
- Top = ar(i, 2)
- cr(ar(i, 1) + 1, 1) = Top
- cr(ar(i, 1), 1) = "0阶"
- cr(ar(i, 1), 2) = Top
- Else
- cr(ar(i, 1) + 1, 1) = ar(i, 2)
- cr(ar(i, 1), 2) = Top
- End If
- .Cells(i, 8) = cr(ar(i, 1), 1) & " | " & cr(ar(i, 1), 2)
- Next
- With Sheet1.Range(Sheet1.Cells(1, 1), Sheet1.Cells(Sheet1.Range("a" & Rows.Count).End(xlUp).Row, Sheet1.Cells(1, Columns.Count).End(xlToLeft).Column))
- .Font.Size = 9
- .Font.Name = "新細明體"
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlBottom
- End With
- End With
- 'Application.ScreenUpdating = True
- MsgBox "材料成本计算完毕" & Chr(10) & "请查核准确性!", vbInformation, "提醒"
- End Sub
复制代码
|
|