excel宏中如何统计某一区域内某个单元格的个数

2024-11-07 01:30:50
推荐回答(2个)
回答1:

统计区域某单元格数量,直接用COUNTIF,非要用VBA的话···········...下边这个是个计数函数,用法就是在单元格内直接写=计数(区域)就好,巨具体你要什么代码,自己参照下吧。
Function 计数(rng As Range) As String
Dim arr As Range, i As Byte, arr1, arr2, mystr As String
With CreateObject("scripting.dictionary")
For Each cell In rng
.Item(cell.Value) = .Item(cell.Value) + 1
Next cell
arr1 = .keys
arr2 = .items
For i = 0 To UBound(arr2)
mystr = mystr & arr1(i) & arr2(i) & ","
Next
End With
计数 = Left(mystr, Len(mystr) - 1)
End Function

回答2:

=COUNTIFS(单元格区域,条件)
用COUNTIFS函数,条件既可以是数字也可以使文本