- Private Sub 材料加工成本_Click()
- Dim d, d1, i&, arr, brr, crr, j, s, total, k&, ar
- tt = Timer
- 'Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- arr = Sheet2.Range(Sheet2.Cells(2, 1), Sheet2.Cells(Sheet2.Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1, Sheet2.Cells.Find("*", , , , xlByColumns, xlPrevious).Column)) '单元格内容不为空的最大行列,不含各种格式.
- For i = 1 To UBound(arr, 1)
- d1(arr(i, 1) & arr(i, 2)) = Array(arr(i, 1), arr(i, 4), arr(i, 5), arr(i, 6))
- Next
-
- ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
- For i = 1 To UBound(arr) - 1
- s = arr(i, 2)
- If d(s) = "" Then
- M = M + 1
- d(s) = M
- brr(M, 1) = arr(i, 2)
- brr(M, 2) = arr(i, 3)
- End If
- Next
-
- With Sheet1
- On Error Resume Next
-
- '.[a3].Resize(M, UBound(brr, 2)).Value = brr
-
- ar = Sheet1.Range(Sheet1.Cells(1, 1), Sheet1.Cells(Sheet1.Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1, Sheet1.Cells.Find("*", , , , xlByColumns, xlPrevious).Column)) '单元格内容不为空的最大行列,不含各种格式.
- ReDim crr(1 To UBound(brr), 1 To UBound(ar, 2))
- For i = 1 To UBound(brr, 1)
- crr(i, 1) = brr(i, 1)
- crr(i, 2) = brr(i, 2)
-
- For k = 1 To 3
- For j = 3 + 13 * (k - 1) To 15 + 13 * (k - 1)
- If d1(brr(i, 1))(0) = ar(2, j) Then
- crr(i, j) = d1(ar(2, j) & brr(i, 1))(k)
- End If
- Next j
-
-
- Next k
- Next i
- .UsedRange.Offset(2).ClearContents
- .[a3].Resize(UBound(brr), UBound(ar, 2)) = crr
- End With
- With Sheet1.Range("a2:AO" & Sheet1.Cells(Rows.Count, 1).End(xlUp).Row)
- .AutoFilter
- .Font.Size = 9
- .NumberFormatLocal = "0.00"
- .Font.Name = "新細明體"
- .HorizontalAlignment = xlLeft
- .VerticalAlignment = xlBottom
- End With
- 'Application.ScreenUpdating = True
- MsgBox "成本按年月更新完毕!" & Chr(10) & "共用 " & Format(Int((Timer - tt) / 3600), "00") & "时" & Format(Int((Timer - tt) / 60) - Int((Timer - tt) / 3600) * 60, "00") & "分" & Format((Timer - tt) - Int((Timer - tt) / 60) * 60, "00") & "秒!", vbInformation, "提示"
- End Sub
复制代码
|