欢迎来到我的博客,本人把技术和生活随想都积累并分享在这里,很高兴遇见你,和你一同进步。

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

 

posted @ 2020-07-24 20:38  Yusuf1111  阅读(580)  评论(0)    收藏  举报