|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("明细")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a2").Resize(r - 1, c)
- End With
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 5)) Then
- m = 1
- ReDim brr(1 To 6, 1 To m)
- Else
- brr = d(arr(i, 5))
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 6, 1 To m)
- End If
- brr(1, m) = m
- brr(2, m) = arr(i, 2)
- brr(3, m) = arr(i, 3)
- brr(4, m) = arr(i, 4)
- brr(5, m) = brr(4, m) * 0.1
- brr(6, m) = brr(4, m) - brr(5, m)
- d(arr(i, 5)) = brr
- Next
- For Each aa In d.keys
- On Error Resume Next
- Worksheets(aa).Delete
- On Error GoTo 0
- brr = d(aa)
- ReDim crr(1 To UBound(brr, 2), 1 To UBound(brr))
- For i = 1 To UBound(brr)
- For j = 1 To UBound(brr, 2)
- crr(j, i) = brr(i, j)
- Next
- Next
- With Worksheets("模板")
- .UsedRange.Offset(4, 0).ClearContents
- .Range("b3") = aa
- .Range("a5").Resize(UBound(crr), UBound(crr, 2)) = crr
- .Copy after:=Worksheets(Worksheets.Count)
- ActiveSheet.Name = aa
- End With
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|