martel_9

New Member
Joined
Jul 5, 2022
Messages
9
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Mobile
I am working on contacts sheet which I need to get the name from email.
Multiple cases I have to faced and with the help of below post link, I formed the sheet below.
Extract name and company from email address

Case 1: The mail id may contain separators like dot, dash and under-score
Case 2: The mail id may contain numbers
Case 3: The mail id may contain upper case letters without separators

Does anyone has an idea to shorten the steps and fix the last two rows issue.
I aim to do everything in one formula or using vba


Contact Database.xlsm
ABCDEFGHIJK
1First NameLast NameNo numbers FnameNo numbers LnameFinal F-NameFinal L-NameCompany NameEmail Address
2FnameLnameFnameLnameFnameLnameHotmailFname_Lname@hotmail.com
3FnameLnameFnameLnameFnameLnameYahooFname.Lname@yahoo.com
4FnameLnameFnameLnameFnameLnameOutlookFname-Lname@outlook.com
5FnameLname3FnameLnameFnameLnameHotmailFname_Lname3@hotmail.com
6Fname1LnameFnameLnameFnameLnameYahooFname1.Lname@yahoo.com
7FnameLnameFnameLnameFnameLnameFnameLnameFnameLnameOutlookFnameLname@outlook.com
8Fname2LnameFname2LnameFnameLnameFnameLnameFnameLnameYahooFname2Lname@yahoo.com
9FnameLname5FnameLname5FnameLnameFnameLnameFnameLnameGmailFnameLname5@gmail.com
10FL.name5FL.nameFL.nameIcloudF.L.name5@icloud.com
11FL-name5FL-nameFL-nameMsnF.L-name5@msn.com
Sheet3
Cell Formulas
RangeFormula
A2:A11A2=LET(MailID,(LEFT($K2,LEN($K2)-LEN((RIGHT($K2,LEN($K2)-FIND("@",$K2))))-1)),Case1,LEFT($K2,LEN($K2)-LEN((RIGHT($K2,LEN($K2)-FIND(".",$K2))))-1),Case2,LEFT($K2,LEN($K2)-LEN((RIGHT($K2,LEN($K2)-FIND("_",$K2))))-1),Case3,LEFT($K2,LEN($K2)-LEN((RIGHT($K2,LEN($K2)-FIND("-",$K2))))-1),(IF(IF(ISERROR(FIND(".",(MailID))),TRUE)=FALSE,Case1,IF(IF(IF(ISERROR(FIND(".",(MailID))),TRUE)=TRUE,IF(ISERROR(FIND("_",(MailID))),TRUE))=FALSE,Case2,IF(IF(IF(IF(ISERROR(FIND(".",(MailID))),TRUE)=TRUE,IF(ISERROR(FIND("_",(MailID))),TRUE))=TRUE,IF(ISERROR(FIND("-",(MailID))),TRUE))=FALSE,Case3,MailID)))))
B2:B11B2=LET(MailID,(LEFT($K2,LEN($K2)-LEN((RIGHT($K2,LEN($K2)-FIND("@",$K2))))-1)),Case1,RIGHT(LEFT($K2,FIND("@",$K2)-1),LEN(LEFT($K2,FIND("@",$K2)-1))-FIND(".",$K2)),Case2,RIGHT(LEFT($K2,FIND("@",$K2)-1),LEN(LEFT($K2,FIND("@",$K2)-1))-FIND("_",$K2)),Case3,RIGHT(LEFT($K2,FIND("@",$K2)-1),LEN(LEFT($K2,FIND("@",$K2)-1))-FIND("-",$K2)),(IF(IF(ISERROR(FIND(".",(MailID))),TRUE)=FALSE,Case1,IF(IF(IF(ISERROR(FIND(".",(MailID))),TRUE)=TRUE,IF(ISERROR(FIND("_",(MailID))),TRUE))=FALSE,Case2,IF(IF(IF(IF(ISERROR(FIND(".",(MailID))),TRUE)=TRUE,IF(ISERROR(FIND("_",(MailID))),TRUE))=TRUE,IF(ISERROR(FIND("-",(MailID))),TRUE))=FALSE,Case3,MailID)))))
D2:D11D2=IFERROR(TEXTJOIN("", TRUE, IF(ISERROR(MID($A2, SEQUENCE(LEN($A2)), 1) *1), MID($A2, SEQUENCE(LEN($A2)), 1), ""))," ")
E2:E11E2=IFERROR(TEXTJOIN("", TRUE, IF(ISERROR(MID($B2, SEQUENCE(LEN($B2)), 1) *1), MID($B2, SEQUENCE(LEN($B2)), 1), ""))," ")
G2:G11G2=PROPER(LEFT($D2,SMALL(FIND(CHAR(ROW(INDIRECT("65:90"))),$D2&"ABCDEFGHIJKLMNOPQRSTUVWXYZ"),2)-1))
H2:H11H2=IF($D2=$G2,$E2,(PROPER(REPLACE($D2,1,LEN($G2),""))))
J2:J11J2=PROPER(LEFT(REPLACE($K2,1,FIND("@",$K2),""),FIND(".",REPLACE($K2,1,FIND("@",$K2),""))-1))
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
How can you guarantee that your list in column K covers all the possible email formats? What about something like JohnFKennedy@whitehouse.gov or FrankLloydWright@architect.com?
Thanks, @6StringJazzer for your reply, There will be no guarantee to cover every case.
In fact, I am trying to cover all possible cases (famous ones) as the mail id does not have a fixed structure.

However, as the excel template that I am trying to design, only includes First and Last Names, your mentioned case and mine in the mini sheet could be resolved by taking the last part (Kennedy) or (Wright) as the last name, while the rest can be in the first name cell (JohnF) or (FrankLloyd).

If we cover that, the exceptional cases will be minimal and can be fixed at the time of appending the contacts.
This formulas -and VBA if needed- will save a huge time for me and my colleagues writing everything manually.
 
Upvote 0
you could use power query
Book1
ABCD
2Fname_Lname@hotmail.comFnameLnamehotmail.com
3Fname.Lname@yahoo.comFnameLnameyahoo.com
4Fname-Lname@outlook.comFnameLnameoutlook.com
5Fname_Lname3@hotmail.comFnameLnamehotmail.com
6Fname1.Lname@yahoo.comFnameLnameyahoo.com
7FnameLname@outlook.comFnameLnameoutlook.com
8Fname2Lname@yahoo.comFnameLnameyahoo.com
9FnameLname5@gmail.comFnameLnamegmail.com
10F.L.name5@icloud.comFLnameicloud.com
11F.L-name5@msn.comFL-namemsn.com
Table1


example code
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"First Name", type text}, {"Last Name", type text}, {"Column1", type any}, {"No numbers Fname", type text}, {"No numbers Lname", type text}, {"Column2", type any}, {"Final F-Name", type text}, {"Final L-Name", type text}, {"Column3", type any}, {"Company Name", type text}, {"Email Address", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"First Name", "Last Name", "Column1", "No numbers Fname", "No numbers Lname", "Column2", "Final F-Name", "Final L-Name", "Column3", "Company Name"}),
    #"Added Custom" = Table.AddColumn(#"Removed Columns", "Nonumbers", each Text.Remove([Email Address],{"0".."9"})),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom", "Nonumbers", Splitter.SplitTextByDelimiter("@", QuoteStyle.Csv), {"Nonumbers.1", "Nonumbers.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Nonumbers.1", type text}, {"Nonumbers.2", type text}}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1", "Nonumbers.1", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Nonumbers.1.1", "Nonumbers.1.2", "Nonumbers.1.3"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Nonumbers.1.1", type text}, {"Nonumbers.1.2", type text}, {"Nonumbers.1.3", type text}}),
    #"Split Column by Delimiter2" = Table.SplitColumn(#"Changed Type2", "Nonumbers.1.1", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Nonumbers.1.1.1", "Nonumbers.1.1.2"}),
    #"Changed Type3" = Table.TransformColumnTypes(#"Split Column by Delimiter2",{{"Nonumbers.1.1.1", type text}, {"Nonumbers.1.1.2", type text}}),
    #"Split Column by Delimiter3" = Table.SplitColumn(#"Changed Type3", "Nonumbers.1.1.1", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Nonumbers.1.1.1.1", "Nonumbers.1.1.1.2"}),
    #"Changed Type4" = Table.TransformColumnTypes(#"Split Column by Delimiter3",{{"Nonumbers.1.1.1.1", type text}, {"Nonumbers.1.1.1.2", type text}}),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Changed Type4", "Nonumbers.1.1.1.1", Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}), {"Nonumbers.1.1.1.1.1", "Nonumbers.1.1.1.1.2"}),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Character Transition",{"Nonumbers.1.1.1.1.2", "Nonumbers.1.1.1.2", "Nonumbers.1.1.2", "Nonumbers.1.2", "Nonumbers.1.3"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"LName")
in
    #"Merged Columns"

1661418119689.png
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top