|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
从网上找到的代码,可以从单元格里提取数字,但是不能提取小数,比如“abc20.11"只能提取,20或者11,不能提取为20.11,求大神修改一下实现小数提取,但是不要求把”abc20/11“,提取成”20/11“,在此感谢大家。。。
Function GetNum(rCell As Range, num As Integer) As Double
Dim Arr1() As String, Arr2() As String
Dim chr As String, Str As String
Dim i As Integer, j As Integer
On Error GoTo line1
Str = rCell.Text
For i = 1 To Len(Str)
chr = Mid(Str, i, 1)
If (Asc(chr) < 48 Or Asc(chr) > 57) Then
Str = Replace(Str, chr, " ")
End If
Next
Arr1 = Split(Trim(Str))
ReDim Arr2(UBound(Arr1))
For i = 0 To UBound(Arr1)
If Arr1(i) <> "" Then
Arr2(j) = Arr1(i)
j = j + 1
End If
Next
GetNum = IIf(num <= j, Arr2(num - 1), "")
line1:
End Function
|
|