|
本帖最后由 yeahwsw 于 2024-7-24 16:39 编辑
统计平行班语文大于等于87分的人数,为什么数组+for循环比调用工作表函数countifs慢,数据总共90多万行
数组方法
Sub te()
Start = Timer
arr = Worksheets("成绩表B").Cells(1, 1).CurrentRegion
For j = 2 To UBound(arr, 1)
If arr(j, 2) = "小班" Then GoTo flag
If arr(j, 5) >= 87 Then s = s + 1
flag:
Next
Finish = Timer
Total = Finish - Start
MsgBox "程序运行了" & Format(Total, "0.0000" & "秒")
Stop
End Sub
耗时
调用工作表函数countifs
Sub td()
Start = Timer
Set Rng_bl = Worksheets("成绩表B").Cells(1, 2).Resize(943601, 1)
Set rng_cj = Worksheets("成绩表B").Cells(1, 5).Resize(943601, 1)
s = WorksheetFunction.CountIfs(Rng_bl, "平行班", rng_cj, ">=" & 87)
Finish = Timer
Total = Finish - Start
MsgBox "ggggg8888程序运行了" & Format(Total, "0.0000" & "秒")
Stop
End Sub
耗时
|
-
-
countifs
-
-
测试.rar
53.74 KB, 下载次数: 17
|