excel2016怎么提取单元格数字?来看看excel提取数字的办法:
1、汉字在前,数字在后面的情形。可以用MID,min, find三个函数来实现提取里面的数字。如图:在B2输入“=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),20)”
2 、把单元格里面所有的数字都提出来。可以使用宏。先打开VBA编辑器。工具宏visual basic 编辑器
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单元格里所有的数字都提取出来了,如图所示。
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
6、在回到单元格那里输入“=Getnums(A3,2)”就可以提取第几次出现的数组了,如图所示。
转载请注明:范的资源库 » excel2016怎么提取单元格数字