在宏中添加以下自定义函数,然后在要显示统计结果的单元格里输入
=CalcNumbers(被统计的范围)
就可以了.
Public Function CalcNumbers(calcRange As Range)
Dim tmpCell As Range Dim newString As String
newString = ""
For Each tmpCell In calcRange
newString = newString & tmpCell.Value
Next
Dim resultString As String
resultString = ""
For i = 0 To 9
counts = Len(newString) - Len(VBA.Replace(newString, i, ""))
resultString = resultString & "[" & i & "]有[" & counts & "]个" & vbCrLf
Next
CalcNumbers = resultString
End Function