Excel用自定义函数提取单元格内字符串中的数字(VBA代码) 20
求提取数字达到右边的效果,请问怎么实现?——————————————————————我试了一个代码,对小数不能实现正确提取,请问怎么解决,请大侠帮忙。FunctionGe...
求提取数字达到右边的效果,请问怎么实现?——————————————————————我试了一个代码,对小数不能实现正确提取,请问怎么解决,请大侠帮忙。Function GetNums(rCell As Range, num As Integer) AsStringDim Arr1() As String, Arr2() As StringDim chr As String, Str As StringDim i As Integer, j As IntegerOn Error GoTo line1Str = rCell.TextFor i = 1 To Len(Str)chr = Mid(Str, i, 1)If (Asc(chr) < 48 Or Asc(chr) > 57) ThenStr = Replace(Str, chr, "")End IfNextArr1 = Split(Trim(Str))ReDim Arr2(UBound(Arr1))For i = 0 To UBound(Arr1)If Arr1(i) <> "" ThenArr2(j) = Arr1(i)j = j + 1End IfNextGetNums = IIf(num <= j, Arr2(num - 1), "")line1:End Function
Function GetNums(rCell As Range, num As Integer) AsString
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
GetNums = IIf(num <= j, Arr2(num - 1), "")
line1:
End Function 展开
Function GetNums(rCell As Range, num As Integer) AsString
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
GetNums = IIf(num <= j, Arr2(num - 1), "")
line1:
End Function 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |