问题
Program: Excel 2010
Require: A way to extract the First Name, Surname, email to individual cells.
Data: My data has a table with original 'dirty data', it's raw and a mess. I tidy it up using a simple =IF(A7="Order",1,"")
, then rest of the cells follow: =IF($C7=1,B13,"")
example:
(A) | Orig2 | Header? (C) | NameAll (K) | Price |
----------------------------------------------------------------------------------------
Order | Ms Admin (e@m.com) | =IF(A7="Order",1,"") | =IF($C7=1,B13,"") | =IF($C7=1,B5,"")
Order | Mr Joe (e@m.com) | =IF(A8="Order",1,"") | =IF($C8=1,B14,"") | =IF($C8=1,B6,"")
Order | Ms Fred (e@m.com) | =IF(A9="Order",1,"") | =IF($C9=1,B15,"") | =IF($C9=1,B7,"")
results in:
(A) | Orig2 | Header? (C) | NameAll (K) | Price |
------------------------------------------------------------------------
Order | Ms Admin (e@m.com) | 1 | Ms Admin (e@m.com) | 13.99
Order | Mr Joe (e@m.com) | 1 | Mr Joe (e@m.com) | 15.99
Order | Ms Fred (e@m.com) | 1 | Ms Fred (e@m.com) | 17.99
Working After I have copied the cell values over, then 'copy/value' on my sheet, I can then use in (U7)
the following (which extracts the email from between ())=IFERROR(MID(K7,(SEARCH("(",K7)+1),((SEARCH(")",K7)-(SEARCH("(",K7)+1)))),"")
What I want to do is take it from the beginning of the data moving, so I can miss the step completely of copying the old, to new, then data extraction
Tried: failed=IFERROR($C7=1,B13(MID(B13,(SEARCH("(",B13)+1),((SEARCH(")",B13)-(SEARCH("(",B13)+1))))))
I also come unstuck with a name such as: W. H. Minder (m@e.net) when trying to separate the First, Middle, Last (email)
Is it just easier that I run through a number of steps?
Thank you in advance.
回答1:
Parsing names is not simple, because of all the variations. One issue with your data as you've shown it would be testing to see if the First Name was really a title like Mr Ms etc.
My preference would be to do this using VBA and regular expressions, but here are some formulas you can play with:
Email: =MID(TRIM(A1),FIND("(",TRIM(A1))+1,FIND(")",TRIM(A1))-FIND("(",TRIM(A1))-1)
First Name: =LEFT(TRIM(A1),FIND(" ",TRIM(A1))-1)
Middle Name: =IF(LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))<>3,"",LEFT(MID(TRIM(A1),FIND(" ",TRIM(A1))+1,99),FIND(" ",MID(TRIM(A1),FIND(" ",TRIM(A1))+1,99))-1))
Last Name: =TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(A1,FIND("(",A1)-1))," ",REPT(" ",99)),99))
The First Name will be the First "Word", so you could test to see if it Mr or Mrs or something you don't want to return.
The Middle Name will be returned if and only if there are three names, but that could be rewritten to return all except the First and Last Names
来源:https://stackoverflow.com/questions/21442485/excel-2010-search-for-text-in-if-function-separate-cell-data