Formula to extract a portion of a name
Hello,,
In Excel I would use text to columns to do what I'm trying to accomplish here but I would like to try a different approach. I'm really close but seem to have hit an impasse.
I have a name column that is formatted thusly Lastname, Firstname MI. where some employees do not have a middle initial. I want a column with the first name only and while I could do a vlookup against another sheet I want to solve it using a formula.
Employee Name contains the "Lastname, Firstname, MI. and the formula I have is:
=RIGHT([Employee Name]@row, LEN([Employee Name]@row) - FIND(", ", [Employee Name]@row))
It gives me Firstname MI so "Smith, John A." shows up as "John A." I'm trying to just have "John."
Thank you,
Khari
Best Answer
-
Hi @Khari Shiver,
This should work for you, I think:
=IFERROR(MID([Employee Name]@row, (FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row))) + 1), (FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row) + 2)) - FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row))) - 1)), RIGHT([Employee Name]@row, LEN([Employee Name]@row) - FIND(", ", [Employee Name]@row)))
This section finds the first name if there is an middle initial present:
(MID([Employee Name]@row, (FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row))) + 1), (FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row) + 2)) - FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row))) - 1))
If there is not a middle initial then this would return an error, so the IFERROR and your original formula then go to work and capture the rightmost portion which should be the first name.
Some sample results:
The only failing of this if the comma between lastname & firstname is absent you will get a result showing both.
Hope this helps, if you've any questions then just ask! 😊
Answers
-
Hi @Khari Shiver,
This should work for you, I think:
=IFERROR(MID([Employee Name]@row, (FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row))) + 1), (FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row) + 2)) - FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row))) - 1)), RIGHT([Employee Name]@row, LEN([Employee Name]@row) - FIND(", ", [Employee Name]@row)))
This section finds the first name if there is an middle initial present:
(MID([Employee Name]@row, (FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row))) + 1), (FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row) + 2)) - FIND(" ", [Employee Name]@row, (FIND(", ", [Employee Name]@row))) - 1))
If there is not a middle initial then this would return an error, so the IFERROR and your original formula then go to work and capture the rightmost portion which should be the first name.
Some sample results:
The only failing of this if the comma between lastname & firstname is absent you will get a result showing both.
Hope this helps, if you've any questions then just ask! 😊
-
Thank you for this! It works and I'm going to take some time to study what you've done.
Khari
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64K Get Help
- 410 Global Discussions
- 220 Industry Talk
- 459 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 137 Just for fun
- 57 Community Job Board
- 459 Show & Tell
- 31 Member Spotlight
- 1 SmartStories
- 298 Events
- 37 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!