天大的发现,就是对于不同的数据源格式zR(i, 3),如文本和整数,在d(zR(i, 3))=""这里的运行速度相差惊人,整数的比文本的要慢80倍!我原来的数目BC列各20多万,如果用整数要用掉大量的时间。代码修改如下:才27秒多就完成: Sub 查已用4() Dim x, y, i, zR, yR Dim d As Object t1 = Timer Application.ScreenUpdating = False x = Range("b1048576").End(xlUp).Row y = Range("c1048576").End(xlUp).Row zR = Range("a1:d" & x) For i = 1 To x zR(i, 2) = "S" & zR(i, 2) If Not zR(i, 3) = "" Then zR(i, 3) = "S" & zR(i, 3) Next i Set d = CreateObject("scripting.dictionary") For i = 1 To y d(zR(i, 3)) = "" Next For i = 1 To x If Not d.exists(zR(i, 2)) Then n = n + 1: zR(n, 4) = zR(i, 2) Next For i = 1 To n zR(i, 4) = Right(zR(i, 4), Len(zR(i, 4)) - 1) Next i For i = 1 To n Range("D" & i) = zR(i, 4) Next i '[d1].Resize(n) = Application.Index(zR, 0, 4) '这句在数量大的时候通不过 Set d = Nothing Application.ScreenUpdating = True Cells(1, 7) = Timer - t1 End Sub 遗憾的是[d1].Resize(n) = Application.Index(zR, 0, 4)这句在数量大的时候通不过。
|