Separating text String with Name Date of birth and other information

SeliM

Board Regular
Joined
Aug 10, 2023
Messages
62
Office Version
  1. 365
Platform
  1. Windows
Thanks for taking time to read my enquiry.

I am trying to separate a text string output from a dataset that has a combined first name, middle Initial, family name, date of birth, hours and cost structure in one cell. The task is to separate into 6 columns.

I have been experimenting with substitute and textsplit which works fine when the delimiter is "-" and date of birth is using a "/". Example:
George E Smith-26/11/1948-26-1785 the formula result is correct across the 6 columns - first name, middle Initial, family name, date of birth, hours and cost

However, there are entries that use the following a "/" instead of "-" and a "-" instead of a "/". The formula of course separates the date of birth into 3 columns when we require one.

Text: George E Smith/26-11-1948/26/1787 is my challenge. I have tried using different methods for the delimiter but either the name doesn't separate as required or the DoB isn't correctly set out.

Your advice would be most welcomed.
Mel
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Assuming your data are in A1, insert:
=SUBSTITUTE(IF(FIND("-",A1)<FIND("/",A1),SUBSTITUTE(A1,"-"," "),SUBSTITUTE(A1,"/"," ")),"-","/")
into B1. This will format the data consistently for parsing. Then insert:
=MID($B1,IF(COLUMN()=3,0,FIND(CHAR(1),SUBSTITUTE($B1&" "," ",CHAR(1),COLUMN()-3)))+1,(FIND(CHAR(1),SUBSTITUTE($B1&" "," ",CHAR(1),COLUMN()-2))-IF(COLUMN()=3,0,FIND(CHAR(1),SUBSTITUTE($B1&" "," ",CHAR(1),COLUMN()-3))))-1)
into C1 and copy across to H1.
Copy down as far as needed.
 
Last edited:
Upvote 0
Solution
Try:
Book1
ABCDEFGHI
1StringFirstMiddleFamilyDayMonthYearCostHour
2George E Smith/26-11-1948/26/1787GeorgeESmith26111948261787
3George E Smith/26/11/1948/26/1787GeorgeESmith26111948261787
Sheet4
Cell Formulas
RangeFormula
B2:I3B2=TEXTSPLIT(A2,{" ","/","-"})
Dynamic array formulas.
 
Upvote 0
Thanks for your time, however we need the DoB as one string 26/11/1948.
 
Upvote 0
If you need the DOB as an actual date rather than just as a string, you could insert -- between = and MID (i.e. =--MID) in column F and format the cell as a date.
 
Upvote 0
How about
Book1
ABCDEFG
1StringFirstMiddleFamilyDOBCostHour
2George E Smith/26-11-1948/26/1787GeorgeESmith26/11/1948261787
3George E Smith/26/11/1948/26/1787GeorgeESmith26/11/1948261787
Sheet1
Cell Formulas
RangeFormula
B2:G3B2=SUBSTITUTE(TEXTSPLIT(IF(ISNUMBER(SEARCH("-",A2)),A2,SUBSTITUTE(SUBSTITUTE(A2,"/","-",2),"/","-",2)),{" ","/"}),"-","/")
Dynamic array formulas.
 
Upvote 0
Using LAMBDA.
Book1
ABCDEFG
1StringFirstMiddleFamilyDOBCostHour
2George E Smith/26-11-1948/26/1787GeorgeESmith26/11/1948261787
3George E Smith/26/11/1948/26/1787GeorgeESmith26/11/1948261787
Sheet1
Cell Formulas
RangeFormula
B2:G3B2=SUBSTITUTE(TEXTSPLIT(IF(ISNUMBER(SEARCH("-",A2)),A2,REDUCE(A2,{"-","-"},LAMBDA(a,b,SUBSTITUTE(a,"/",b,2)))),{" ","/"}),"-","/")
Dynamic array formulas.
 
Upvote 0
Thanks very much
I now have a variety of solutions that help with the various input styles in the data.
:)
 
Upvote 0
No problem. I've missed a few cases. This should cover all
Book1
ABCDEFG
1StringFirstMiddleFamilyDOBCostHour
2George E Smith/26-11-1948/26/1787GeorgeESmith26/11/1948261787
3George E Smith/26/11/1948/26/1787GeorgeESmith26/11/1948261787
4George E Smith-26/11/1948-26-1785GeorgeESmith26/11/1948261785
5George E Smith-26-11-1948-26-1785GeorgeESmith26/11/1948261785
6George E Smith-26/11/1948-26/1785GeorgeESmith26/11/1948261785
Sheet1
Cell Formulas
RangeFormula
B2:G6B2=LET(s,SUBSTITUTE(A2,"-","/"),t,SUBSTITUTE(TEXTSPLIT(REDUCE(s,{"-","-"},LAMBDA(a,b,SUBSTITUTE(a,"/",b,2))),{" ","/"}),"-","/"),IFERROR(--t,t))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,803
Messages
6,181,055
Members
453,015
Latest member
ZochSteveo

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