標題:
[發問]
for next 迴圈速度慢,如何改速度能加快
[打印本頁]
作者:
chiang0320
時間:
2016-12-2 16:41
標題:
for next 迴圈速度慢,如何改速度能加快
[attach]25998[/attach] [attach]25999[/attach]
M欄為變數,有可能數量會到十萬或二十萬...
利用迴圈速度很慢,如何可以加快速度
Public Sub WWW()
Start = Timer
Range("K3") = "=COUNTIF(M:M,""*RBW*"")"
a = Range("K3")
For i = 4 To a + 3
Cells(i, "N") = "=IFERROR(AVERAGEIF($D:$H,M" & i & ",E:H),""0"")"
Cells(i, "O") = "=IFERROR(COUNTIF(D:D,M" & i & "),""0"")"
Next i
Range("M:O").Value = Range("M:O").Value
Finish = Timer
TotalTime = Finish - Start
MsgBox "已完成! 總共:" & TotalTime & "秒 !"
End Sub
作者:
准提部林
時間:
2016-12-2 22:02
Sub WWW()
Dim Arr, Brr, xD, i&, j%, N&, SS, TM
TM = Timer
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([M4], Cells(Rows.Count, "M").End(xlUp))
ReDim Brr(1 To UBound(Arr), 1 To 2)
For i = 1 To UBound(Arr)
If Arr(i, 1) <> "" Then xD(Arr(i, 1)) = i
Next i
Arr = Range([D4], Cells(Rows.Count, "D").End(xlUp)(1, 5))
For i = 1 To UBound(Arr)
N = xD(Arr(i, 1)): If N = 0 Then GoTo 101
SS = Split(Mid(Brr(N, 1), 2) & "/", "/")
For j = 2 To 5
If IsNumeric(Arr(i, j)) Then
SS(0) = Val(SS(0)) + Arr(i, j)
SS(1) = Val(SS(1)) + 1
End If
Next j
Brr(N, 1) = "=" & SS(0) & "/" & SS(1) '=總合計/個數
Brr(N, 2) = Brr(N, 2) + 1
101: Next i
[N4].Resize(UBound(Brr), 2) = Brr
MsgBox "已完成! 總共:" & Timer - TM & "秒 !"
End Sub
複製代碼
[attach]26001[/attach]
作者:
chiang0320
時間:
2016-12-5 21:06
回復
2#
准提部林
Dear 准提部林 :
謝謝幫忙,跑完才花費不到一秒鐘
對於初學持者但太深奧了!很想學起來但不知如何問起 =_=
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)