|
楼主 |
发表于 2023-4-20 15:52
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
下面无事,根据网友的代码,我又编制了两段代码,主要是对无序的项目进行数据汇总和表格转换,并作了速度对比。
代码如下:
- Sub 用字典表格转换() '8千行无序10.56秒,'有序5.59秒
- '字典'可对无序的项目进行汇总
- Dim arr, brr, i, d
- Set d = CreateObject("Scripting.Dictionary")
- Range("D2").CurrentRegion.ClearContents
- T = Timer
- arr = Range("A1").CurrentRegion
- For i = 2 To UBound(arr)
- d(arr(i, 1)) = d(arr(i, 1)) & "|B" & i '装单元格的文本地址
- Next
- For i = 0 To d.Count - 1
- brr = d.items
- brr = Split(brr(i), "|")
- For j = 1 To UBound(brr)
- Cells(i + 2, j + 4) = Range(brr(j))
- Next
- Next
- Range("d" & 2).Resize(d.Count, 1) = _
- WorksheetFunction.Transpose(d.keys)
- Set d = Nothing
- MsgBox Timer - T
- End Sub
- Sub 坛友编的() '8千行无序10.86秒,'有序4.9秒
- Dim arr, brr, i, d
- Set d = CreateObject("Scripting.Dictionary")
- 'Sheet2.Activate
- Range("D2").CurrentRegion.ClearContents
- T = Timer
- js = 0
- For i = 1 To [A65500].End(3).Row
- x = Cells(i, 1)
- If d.exists(x) Then
- Cells(d(x), Cells(d(x), 2000).End(1).Column + 1) = Cells(i, 2)
- Else
- d(x) = js + 1
- js = js + 1
- Cells(d(x), 4) = Cells(i, 1)
- Cells(d(x), 5) = Cells(i, 2)
- End If
- Next
- MsgBox Timer - T
- Set d = Nothing
- End Sub
复制代码
|
|