要看你怎么对待字母,可以写一个函数,用自己需要的字符替代字母(也可以是空字符),函数如下:
Function onlynum(a As String, b As String) As Double
Dim i As Integer, c As String, d As String
d = ".0123456789"
If b <> "" Then b = Val(Left(b, 1))
For i = 1 To Len(a)
If InStr(d, Mid(a, i, 1)) > 0 Then
c = c & Mid(a, i, 1)
Else
c = c & b
End If
Next
onlynum = Val(c)
End Function
函数调用示范:
a=onlynum("a1234b.cd233","")
结果:a=1234.233,所有字母都被去掉
a=onlynum("a1234b.cd233","a") 结果:a=12340.00233,所有英文字母被0替代
a=onlynum("a1234b.cd233","5") 结果:a=512345.55233,所有英文字母被5替代