Excel CountA、CountIf,二者的比較
如果先把資料整理好,有順序的話,那麼使用countA,會快很多
'統計機率
Dim i As Integer, j As Integer
lLastRow = ShtXy.Range("A" & Cells.Rows.Count).End(xlUp).Row
Set myTbl = ShtXy.Range("A" & lLastRow).CurrentRegion
For j = 1 To All_Ball
If j < 10 Then
chkBall = "0" & j
Else
chkBall = j
End If
Per_x = Application.CountA(myTbl.Columns(j + 2)) '改這樣變更快,資源佔用少
'Per_x = Application.CountIf(myTbl, chkBall) '舊程式
With ShtTmp
i = 1
.Cells(j + 2, i + 1) = Per_x '次數
.Cells(j + 2, i + 2) = chkBall '球號
.Cells(j + 2, i + 3) = arrShowBallCon(j) '落號距離
End With
Next
'統計機率
Dim i As Integer, j As Integer
lLastRow = ShtXy.Range("A" & Cells.Rows.Count).End(xlUp).Row
Set myTbl = ShtXy.Range("A" & lLastRow).CurrentRegion
For j = 1 To All_Ball
If j < 10 Then
chkBall = "0" & j
Else
chkBall = j
End If
Per_x = Application.CountA(myTbl.Columns(j + 2)) '改這樣變更快,資源佔用少
'Per_x = Application.CountIf(myTbl, chkBall) '舊程式
With ShtTmp
i = 1
.Cells(j + 2, i + 1) = Per_x '次數
.Cells(j + 2, i + 2) = chkBall '球號
.Cells(j + 2, i + 3) = arrShowBallCon(j) '落號距離
End With
Next
留言
張貼留言