问题
I've got a column where cells contain phone numbers in the following format:
To: +6112312414 Will Smith To: +61832892357 Tom Hopkins To: +447857747717 Julius Caesar
Or
From: +44712423110 Jack Russel To: 112312414 Mr XYZ To: +61832892357 Hulk
I need to extract the recipient phone numbers in a separate column, names not required e.g.
+6112312414, +61832892357, +447857747717
for the first example and 112312414, +61832892357
for the second example. Can someone please help with this? Thanks!
回答1:
Try the following User Defined Function:
Public Function PhoneList(st As String) As String
Dim v As String
PhoneList = ""
v = Replace(st, "To: ", Chr(1))
arr = Split(v, " ")
For Each a In arr
If InStr(a, Chr(1)) > 0 Then
PhoneList = PhoneList & ", " & a
End If
Next a
PhoneList = Replace(PhoneList, Chr(1), "")
PhoneList = Mid(PhoneList, 3, 9999)
End Function
回答2:
You could extract the data from the column using text to column. Apply the other method and select the colon as extraction :. Then you would be left with the a 'space'+number...note the 'space' denotes just one white space. Next, use the replace all column to remove the space, and you are left with just the +number.
回答3:
Select a blank cell that is adjacent to the list you want to extract number only, and type this formula =SUMPRODUCT(MID(0&A2,LARGE(INDEX(ISNUMBER(--MID(A2,ROW($1:$25),1))* ROW($1:$25),0),ROW($1:$25))+1,1)*10^ROW($1:$25)/10)
(A2 stands the first data you want to extract numbers only from the list), then press Shift + Ctrl + Enter buttons, and drag the fill handle to fill the range you need to apply this formula.
回答4:
Use TEXTJOIN as an array
=TEXTJOIN(", ",TRUE,IF(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),(ROW($A$1:INDEX(A:A,LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1))-1)*99+1,99))="To:",TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),(ROW($A$1:INDEX(A:A,LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1)))*99+1,99)),""))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
TEXTJOIN was introduced with Office 365 Excel
回答5:
First you should convert the cell to columns, after that you should go to a blank cell and write this command =B1 & " " & "," & " " & F1 & " " & "," & " " & J1
this command is for your first example because the reference cells in the command contain the numbers if you want to apply the same command just modify the reference cell as you want
来源:https://stackoverflow.com/questions/52523479/extract-numbers-from-cell-in-excel