EXCEL表格怎么统计出出现次数最多的那数字?重赏,在线等!

EXCEL表格中比较说有五组数据,12345、52681、01951、89621、88031,怎么样才可以统计出出现次数最多的那个数字,在这里我要统计出来的结果是要1,每一组数据中不管出现几次,我都只归为1次,比如01951,这里的1只统计1次,可是这个数字0开头,那我又得把这个格式改成文本格式,那这种情况下呢,又怎么可以统计出我要的1呢?再一个是如果我换五组数据12345、52681、01251、89621、88021,这样统计出来,我需要的结果是1和2,因为他们出现的次数是一样的,请高人指点,谢谢。

这个基本上只有用宏来做了。我写了一个自定义函数。用法如下:
=MyCount(A1:A5),=MyCount(A1:A5,B4:B5) 都行的。括号中的参数就是需要统计的单元格。
-------------如下是代码---------------
Option Explicit
Option Base 1

Function MyCount(ParamArray SomeThing()) As String
Dim myResult(10, 2) As Integer, tmpStr As String
Dim m1, m2 As Range
For Each m1 In SomeThing
For Each m2 In m1
'单个检查字符情况,放到tmpArr中
tmpStr = CountOne(m2.Value)
'将tmpArr中结果并入myResult中
Call CountAdd(myResult, tmpStr)
Next m2
Next m1
MyCount = GetResult(myResult) '从myResult中选出结果
End Function

Private Function CountOne(tmpStr As String) As String
Dim i As Integer, tmp As String
CountOne = ""
For i = 1 To Len(tmpStr)
tmp = Mid(tmpStr, i, 1)
If tmp >= "0" And tmp <= "9" Then '非数字忽略
If InStr(1, CountOne, tmp) = 0 Then CountOne = CountOne & tmp
End If
Next i
End Function

Private Function CountAdd(myResult() As Integer, tmpStr As String)
Dim i As Integer, j As Integer, tmp As String
Dim WriteOK As Boolean
For i = 1 To Len(tmpStr)
tmp = Mid(tmpStr, i, 1)
WriteOK = False
For j = 1 To UBound(myResult, 1)
If myResult(j, 1) = 0 And myResult(j, 2) = 0 Then Exit For
If CInt(tmp) = myResult(j, 1) Then
myResult(j, 2) = myResult(j, 2) + 1
WriteOK = True
End If
Next j
If Not WriteOK Then
myResult(j, 1) = tmp
myResult(j, 2) = 1
End If
Next i
End Function

Private Function GetResult(myResult() As Integer) As String
Dim max As Integer, i As Integer
max = 0
For i = 1 To UBound(myResult, 1)
If myResult(i, 1) = 0 And myResult(i, 2) = 0 Then Exit For
If myResult(i, 2) > max Then max = myResult(i, 2)
Next i
GetResult = ""
For i = 1 To UBound(myResult, 1)
If myResult(i, 1) = 0 And myResult(i, 2) = 0 Then Exit For
If myResult(i, 2) = max Then GetResult = GetResult & CStr(myResult(i, 1))
Next i
End Function

有疑问,请Hi我或给我发百度消息
GoodLuck!
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-04-17
单栏点击fx,fx是函数
相似回答