返回首页
当前位置: 主页 > Excel教程 > Excel函数教程 >

EXCEL 自定义函数提取字符串中的数字

时间:2012-06-17 02:28来源:Office教程学习网 www.office68.com编辑:麦田守望者

自定义函数提取字符串中的数字

Function GetNB(rng As Range)
If rng <> "" Then
For i = 1 To Len(rng)
tmp = Mid(rng, i, 1)
If IsNumeric(tmp) Or tmp Like "[+-\*\/^%)()]" And Not tmp Like "[A-Z?!~@=_,;|\[]" Then GetNB = GetNB & tmp
Next
Else
GetNB = ""
End If
End Function

若使运算式自动计算,则用以下代码

Function CountNB(rng As Range)
If rng <> "" Then
For i = 1 To Len(rng)
tmp = Mid(rng, i, 1)
If IsNumeric(tmp) Or tmp Like "[+-\*\/^%()]" And Not tmp Like "[A-Z?!~@=_,;|\[]" Then CountNB = CountNB & tmp
Next
CountNB = Application.Evaluate(CountNB)
Else
CountNB = ""
End If
End Function

------分隔线----------------------------
标签(Tag):excel excel2007 excel2010 excel2003 excel技巧 excel教程 excel实例教程 excel2010技巧
------分隔线----------------------------
推荐内容
猜你感兴趣