自定义了VBA函数,打算分开以逗号分隔的字符串,并计算其中的数字个数,请求大神的帮助。谢谢。 50
OptionExplicitFunctionSeparate(SlotAsRange)AsIntegerDimParts()AsString,NAsInteger,iAs...
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
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询