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

  • 来源: office教程学习网   2016-06-06/17:00
  • 自定义函数提取字符串中的数字

    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


    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多