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
展开
 我来答
电车痴汉484
2017-04-08 · TA获得超过175个赞
知道答主
回答量:284
采纳率:0%
帮助的人:81.5万
展开全部

得看你的字符串啥样子的!


  1. 单个数字组,比如: "122test"、逗te344st地、"test987",这种用内置函数就可以;

  2. 多个数字组,比如:逗233test3444test533地;这种都要提取的话得用VBA正则表达式;

追问
逗233test3444test533地
这样的能否给我一个VBA的正则表达式
谢谢
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式