在Excel中将移动号码提取到其他单元格

我在一些单元格A1,A2,A3,A4中有非结构化的数据,并且想要在不同的单元格中提取手机号码

--------------------------(A)-------------------------- (1) `ABCDEFG CFGHJKL 9810642882 9212451029 9818682274` (2) `ABCDERFT 9910077711 9811195125 9999966744` (3) `ADFRTYU.9810851029 9818218521 9811056189` (4) `ADFGT FTYUH 9873155802` 

单元格A1的结果:

  ----(A)--- ----(B)--- ----(C)--- (1) 9810642882 9212451029 9818682274 

对于公式唯一的解决scheme,在单元格B1中复制和上下:

 =TRIM(MID(SUBSTITUTE(TRIM(MID($A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},$A1&1234567890)),999))," ",REPT(" ",999)),999*(COLUMN(A1)-1)+1,999)) 

Nitin Jain的tigeravatar示例

您可以使用Excel中内置的“文本到列”function。

突出显示列A并转到数据>>文本到列。 select“分隔”,然后select“空格”作为分隔符。 单击完成,它将按空间拆分数据并将其写出到相邻的列。


对于VBA UDF,您可以使用超方便的SPLIT()string方法,该方法将string以分隔符分隔到数组。 然后,select你需要的位置:

 Public Function strtok(strIn As String, delim As String, token As Integer) As String 'Split the <strIn> by the <delim> outputting the string at position <token> strtok = Split(strIn, delim)(token - 1) End Function 

在工作表中使用这个:

 =strtok(A1," ", 1) 

这将返回string在你的A1值的第一个位置时,空间分割。 如果你把它放在B1那么你可以使用Column()来使它更加dynamic,所以你可以直接拖动公式:

 =strtok($A1," ",Column()-1) 

这里是对上述function的编辑,它将被delim分割,然后用split中的数字值重build一个数组,然后输出从数字数组请求的标记:

 Public Function strtok(strIn As String, delim As String, token As Integer) As String 'Split the strIn by the delim outputting the string at position <token> Dim strArr As Variant 'array to split the initial string Dim numArr() As Double 'array to hold just numeric values Dim arrEl As Variant 'Element for the array 'fill strArr strArr = Split(strIn, delim) 'initial numArr() ReDim numArr(0 To 0) 'Loop through each element in the strArr For Each arrEl In strArr If IsNumeric(arrEl) Then 'resize the numArr to hold a new value If numArr(0) <> 0 Then ReDim Preserve numArr(0 To UBound(numArr) + 1) 'write the value numArr(UBound(numArr)) = arrEl End If Next arrEl strtok = numArr(token - 1) End Function