How to extract names with variable lenths from text strings using Excel?

Molar

New Member
Joined
Mar 7, 2018
Messages
6
I need to extract names from a text string but they are variable in length.
See example below:

PETER PAN PO LLL555555D AUB-1111111 2/27/10 1079.65 1012348
SUPERHERO MAN GGG444444C AUB-0000000 8/02/10 108.00 704546
SUPERHERO WOMAN PO GSS011111F AUB-1111111 3/13/10 11.26 1028549

The names I am trying to extract are:
PETER PAN
SUPERHERO MAN
SUPERHERO WOMAN

How would you do this?
 
The below formula will only work when the customer name does NOT container numbers.

=IF(LEFT(RIGHT(LEFT($A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))-4),4),1)=" ",LEFT($A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))-4-4),LEFT($A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))-4-1))


To break the formula down, this formula does this:

  • It identifies the position of the first number in the cell
=MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A14&"0123456789"))

  • It looks up the value four cells to the left of the first number.
=LEFT(RIGHT(LEFT($A1,$C1-4),4),1)​

  • If fourth cell before the first number is a space, then the two letter code (PO) is applicable, otherwise the assumption is no two letter code.
=IF(STEP2=" ",LEFT($A1,STEP1-4),LEFT($A1,STEP1-1))​

Two possible issues:


  • A customer name with a number in it will give bad results
  • A customer name that ends with a two letter string will give bad results.
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

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