|
原帖由 灰袍法师 于 2010-12-10 16:11 发表
其实我现在发现,UNION跟 利用字符串 Set RANGE 一样
只能线性降低耗时,所以最终速度没差多少
原因是
1 字符串SET RANGE存在255字符长度限制,所以只能把 100万个区域合并为 255/ 5到16 大概是20-30倍 ...
100W光分出地址就要1.6秒,无论怎样组合,上色在2.5秒已是极限。象下面,上色要1.2W次,如果能用with Range(Mid(s, 2)).Interior,可以减少1秒多,可惜动态区域没法办到。
Sub Test()
SJY 1000000
[a:a].ClearFormats
t = Timer
Application.ScreenUpdating = False
n = Cells(1048576, 1).End(3).Row
nl = Len(n)
r = Range("a1:a" & n)
i = 1
While i < n - 1
While r(i, 1) >= 60
i = i + 1
Wend
j = i
While r(i, 1) < 60 And i < n
i = i + 1
Wend
If i = j + 1 Then s = s & ",A" & i - 1 Else s = s & ",A" & j & ":A" & i - 1
If Len(s) > 252 - 2 * Len(i - 1) Then
'Range(Mid(s, 2)).Interior.ColorIndex = 3
s = ""
k = k + 1
End If
Wend
'If s <> "" Then Range(Mid(s, 2)).Interior.ColorIndex = 3
'If r(n, 1) < 60 Then Cells(n, 1).Interior.ColorIndex = 3
Application.ScreenUpdating = True
[d1] = "K值:": [e1] = k
[d2] = "用时:": [e2] = Timer - t
End Sub
Sub SJY(n)
Dim a()
[a:a].Clear
ReDim a(1 To n, 1 To 1)
For i = 1 To n
a(i, 1) = Int(Rnd() * 100) + 1
Next
[a1].Resize(n) = a
End Sub |
|