:个字符的出现次数(自定义函数法)
个字符的出现次数(自定义函数法)
Function test(X, S As String) As Integer
Dim I%, J%
I = Len(X)
J = 1 To I
If Mid(X, J, 1) = "s" Then test = test + 1
Next
End Function
用这个自定义函数也可以
比如A1的内容是:asdsd
你在a2输入: =test(a1,"s")
或者想计算 d 有几个
=test(a1,"d")
自定义函数比宏(过程sub ***() …… end sub)灵活一点
*****************************************************************
根据蓝色幻想版主的提示,还可以自定义函数改修为:
Function test(X, S As String) As Integer
test = Len(X)-len(replace(x,s,""))
End Function