|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- vs = [{"原始数据",8;"收入",9;"发出",13;"退料",9}]
- For k = 1 To UBound(vs)
- With Worksheets(vs(k, 1))
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(r - 1, c)
- m = 0
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- ReDim brr(1 To 17)
- m = m + 1
- brr(1) = m
- For j = 2 To 5
- brr(j) = arr(i, j)
- Next
- brr(7) = arr(i, 7)
- brr(17) = arr(i, vs(k, 2))
- Else
- brr = d(arr(i, 2))
- End If
- If k = 1 Then
- brr(6) = brr(6) + arr(i, 6)
- Else
- brr(k * 2 + 5) = brr(k * 2 + 5) + arr(i, 6)
- brr(k * 2 + 6) = brr(k * 2 + 6) + arr(i, 8)
- End If
- d(arr(i, 2)) = brr
- Next
- End With
- Next
-
- brr = Application.Transpose(Application.Transpose(d.items))
- For i = 1 To UBound(brr)
- brr(i, 8) = brr(i, 6) * brr(i, 7)
- brr(i, 15) = brr(i, 6) + brr(i, 9) - brr(i, 11) + brr(i, 13)
- brr(i, 16) = brr(i, 8) + brr(i, 10) - brr(i, 12) + brr(i, 14)
- Next
- With Worksheets("库存")
- .UsedRange.Offset(2, 0).ClearContents
- .Columns(2).NumberFormatLocal = "@"
- .Range("a3").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|