EXCEL VBA:Excel统计出现次数、个数的VBA代码

2013-10-29 22:31 阅读 623 次 评论关闭

使用如下的VBA代码,您就可以在Excel中,统计某个字符或某个数字,甚至是某个字符串,在某个数据区域范围内,所出现次数,即出现几次,或称为有几个。

代码如下,是VBA宏代码。

Set myb = CreateObject("scripting.dictionary"): myb("数字") = "次数"
Set rng = Application.InputBox("选择要统计的区域:", Type:=8)
ActiveSheet.Cells.Interior.ColorIndex = 0
rng.Interior.ColorIndex = 3
For Each rng1 In rng
myb(rng1.Value) = Application.WorksheetFunction.CountIf(rng, rng1)
Next
Set rng3 = Application.InputBox("选择结果输出地:", Type:=8)
With rng3
.Resize(myb.Count) = Application.Transpose(myb.keys)
.Offset(, 1).Resize(myb.Count) = Application.Transpose(myb.items)
End With
Set myb = Nothing: Set rng3 = Nothing
End Sub

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:EXCEL VBA:Excel统计出现次数、个数的VBA代码 | 猎微网

评论已关闭!