Excel怎么只提取表格中的数字 3、在编辑器里点击插入——模块。在模块那里输入如下代码: Function zzsz(xStr As String) As StringDim i As IntegerFor i = 1 To Len(xStr)If IsNumeric(Mid(xStr, i, 1)) Then zzsz = zzsz & Mid(xStr, i, 1)NextEnd Function 4、回到工作表,在B2单元格那里输入“=zzsz(A2)”。就可以用VBA把A2单元格里所有的数字都提取出来了,如图所示。
Excel怎么只提取表格中的数字 5、指定从第几个数组提取开始。也就是说在不连续的那些数字中,从第几次出现的数组开始提取。同样在模块那里输入如下代码: Function GetNums(rCell As Range, num As Integer) As StringDim Arr1() As String, Arr2() As StringDim chr As String, Str As StringDim i As Integer, j As IntegerOn Error GoTo line1 Str = 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 IfNext Arr1 = Split(Trim(Str))ReDim Arr2(UBound(Arr1))For i = 0 To UBound(Arr1)If Arr1(i) 《》 “” ThenArr2(j) = Arr1(i)j = j + 1End IfNext GetNums = IIf(num 《= j, Arr2(num – 1), “”)line1:End Function