|
我有个表数据量大概有十万,用字典统计每次要运行十几分钟,查了很多字典说写入内存可以提高运行效率,但是根据帖子改了好几次都失败,只能请教各位老师帮忙。把数据表里的内容统计到渠道表。原数据和代码较多,我只发了部分数据和代码。这个是代码
- Sub 测试()
- With ThisWorkbook.Sheets("数据表")
- Set dic1 = CreateObject("scripting.dictionary")
- Set dic2 = CreateObject("scripting.dictionary")
- For i = 2 To .UsedRange.Rows.Count
- dic1(.Cells(i, 2) & .Cells(i, 3) & .Cells(i, 4)) = dic1(.Cells(i, 2) & .Cells(i, 3) & .Cells(i, 4)) + 1
- If .Cells(i, 5) = "是" Then
- dic2(.Cells(i, 2) & .Cells(i, 3) & .Cells(i, 4)) = dic2(.Cells(i, 2) & .Cells(i, 3) & .Cells(i, 4)) + 1
- End If
- Next
- End With
- With ThisWorkbook.Sheets("渠道表")
- For i = 2 To .UsedRange.Rows.Count
- .Cells(i, 4) = dic1(.Cells(i, 1) & .Cells(i, 2) & .Cells(i, 3))
- .Cells(i, 5) = dic2(.Cells(i, 1) & .Cells(i, 2) & .Cells(i, 3))
- Next
- End With
- End Sub
复制代码 这个是附件,谢谢各位。
测试.rar
(23.15 KB, 下载次数: 13)
|
|