excel提取數(shù)字的方法步驟詳解
excel提取數(shù)字的方法步驟詳解
當我們在使用Excel進行辦公的時候,我們可能會遇到一些數(shù)據(jù)需要進行特殊提取的情況,下面小編就為你們介紹excel怎么提取數(shù)字。希望對你有幫助!
excel提取數(shù)字的辦法
1、漢字在前,數(shù)字在后面的情形??梢杂肕ID,min, find三個函數(shù)來實現(xiàn)提取里面的數(shù)字。如圖:在B2輸入“=MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),20)”
excel提取數(shù)字的步驟圖1
2 、把單元格里面所有的數(shù)字都提出來??梢允褂煤?。先打開VBA編輯器。工具——宏——visual basic 編輯器
excel提取數(shù)字的步驟圖2
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單元格里所有的數(shù)字都提取出來了,如圖所示。
excel提取數(shù)字的步驟圖3
5、指定從第幾個數(shù)組提取開始。也就是說在不連續(xù)的那些數(shù)字中,從第幾次出現(xiàn)的數(shù)組開始提取。同樣在模塊那里輸入如下代碼:
復制內容到剪貼板
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
excel提取數(shù)字的步驟圖4
6、在回到單元格那里輸入“=Getnums(A3,2)”就可以提取第幾次出現(xiàn)的數(shù)組了,如圖所示。
excel提取數(shù)字的步驟圖5