|
- Sub test()
- Dim i&
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- t = Timer
- With Worksheets("原始数据")
- arr = .Range("a1").CurrentRegion
- End With
- For i = 2 To UBound(arr) - 1
- kk = Split(arr(i, 2), "-")
- If Not d.exists(kk(0)) Then
- ReDim brr(1 To 2)
- brr(1) = kk(0)
- Else
- brr = d(kk(0))
- End If
- brr(2) = brr(2) + arr(i, 3)
- d(kk(0)) = brr
- Next
- ReDim arr(1 To d.Count, 1 To 3)
- For Each aa In d.keys
- brr = d(aa)
- n = n + 1
- For i = 1 To UBound(brr)
- arr(n, 1) = n
- arr(n, i + 1) = brr(i)
- Next
- Next
- With Worksheets("输出表")
- .Range("a2").Resize(.Rows.Count - 1, 4).ClearContents
- .Range("a2").Resize(UBound(arr), UBound(arr, 2)) = arr
- End With
- Sheets("输出表").Select
- Sheets("输出表").Copy
- ChDir "E:\BaiduNetdiskWorkspace\data\Excel Home" '目录自己换
- ActiveWorkbook.SaveAs Filename:= _
- "E:\BaiduNetdiskWorkspace\data\Excel Home\资料清单.xlsx", FileFormat:= _
- xlOpenXMLWorkbook, CreateBackup:=False
- Application.ScreenUpdating = True
- MsgBox Format(Timer - t, "0.00") & "秒 输出完毕!"
- End Sub
复制代码 |
|