以下是引用figfig在2005-6-30 21:03:49的发言:重点一讲!!第5讲: 数组 取代 RANGE,速度快5--10 倍!! Sub Test1() Dim i As Long, j As Long, buf As Long For i = 1 To 10000 For j = 1 To 100 buf = Cells(i, j) Next j Next i End Sub Sub Test2() Dim i As Long, j As Long, buf As Long, C As Variant C = Range("A1:CV10000") For i = 1 To 10000 For j = 1 To 100 buf = C(i, j) Next j Next i End Sub 经检验,数组比单个值快,快不止10倍,如果用秒表计算,快得更多.如下图:
如果想亲自测试,请用如下代码,然后分别运行. Sub Test1() Dim i As Long, j As Long, buf As Long Cells(1, 1).FormulaR1C1 = "=NOW()" Cells(1, 1).NumberFormatLocal = "hh""时""mm""分""ss""秒""" With Cells(1, 1) .Copy .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False End With Application.CutCopyMode = False For i = 1 To 10000 For j = 1 To 100 buf = Cells(i, j) Next j Next i Cells(1, 2).FormulaR1C1 = "=NOW()" Cells(1, 2).NumberFormatLocal = "hh""时""mm""分""ss""秒""" End Sub Sub Test2() Dim i As Long, j As Long, buf As Long, C As Variant Cells(2, 1).FormulaR1C1 = "=NOW()" Cells(2, 1).NumberFormatLocal = "hh""时""mm""分""ss""秒""" With Cells(1, 1) .Copy .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False End With Application.CutCopyMode = False C = Range("A1:CV10000") For i = 1 To 10000 For j = 1 To 100 buf = C(i, j) Next j Next i Cells(2, 2).FormulaR1C1 = "=NOW()" Cells(2, 2).NumberFormatLocal = "hh""时""mm""分""ss""秒""" End Sub
[此贴子已经被作者于2006-12-4 22:35:53编辑过] |