使用如下的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