VBA 统计数据
Sub CountTest()
Dim mycount As Integer, rng As Range
For Each rng In Range("A1:B50")
If rng.Value > 1000 Then mycount = mycount + 1
Next
MsgBox "大于1000的个数有:" & mycount
End Sub
运行结果如下:

这个问题,如果要使用工作表中的countif 函数来解决,可以将代码写成:
Sub CountTest()
Dim mycount As Integer
mycount = Application.WorksheetFunction.CountIf(Range("A1 :B50"), ">1000")
MsgBox "大于1000的数据个数为:" & mycount
End Sub
联系QQ邮箱:2433973080@qq.com

浙公网安备 33010602011771号