Option ExplicitFunction Separate(Slot As Range) As IntegerDim Parts() As String, N As Integer, i As Integer '对字符串进行拆分,分成数组PartsParts = Split(Slot.Value, ",")N = 0 '判断数组元素个数的上限For i = 0 To 100 If Parts(i) <> "" Then Else N = i Exit For End IfNext iFor i = 0 To N '清洗数据,把一些不必要的符号全部去掉 Parts(i) = Replace(",", "", 2) Parts(i) = Replace(";", "", 2) Parts(i) = Replace("[", "", 2) '如果是一位数字或两位数字则计入统计 If Parts(i) Like "#" Or Parts(i) Like "##" Then i = i + 1 Else '返回最终结果Separate,即需要统计的数字个数 Separate = i + 1 End IfNext iEnd Function