Textsplit loses Delimiter

pto160

Well-known Member
Joined
Feb 1, 2009
Messages
505
Office Version
  1. 365
Platform
  1. Windows
I am trying to split text by a delimiter, but I want the delimiter to remain. It does not seem to work. I want the text to split text by "CZ" in this example.
Is there a way to do this?

Book3
AB
2CZ DOG ER CZ DOG EE CZ CAT ER CZ CAT EE CZ SNAKE EE CZ SNAKE ER CZ HOUSE EE CZ HOUSE ER 
3 DOG ER
4 DOG EE
5 CAT ER
6 CAT EE
7 SNAKE EE
8 SNAKE ER
9 HOUSE EE
10 HOUSE ER
11
12What I like
13CZ DOG ER
14CZ DOG EE
15CZ CAT ER
16CZ CAT EE
17CZ SNAKE EE
18CZ SNAKE ER
19CZ HOUSE EE
20CZ HOUSE ER
Sheet2
Cell Formulas
RangeFormula
B2:B10B2=TEXTSPLIT(A2,,"CZ")
Dynamic array formulas.
 
You can simply concatenate the delimiter:
Excel Formula:
=TRIM("CZ " & TEXTSPLIT(A2,,"CZ",1))

Another alternative.
Excel Formula:
=TEXTSPLIT(SUBSTITUTE(A2,"CZ ","|CZ "),,"|",1)
 
Upvote 0
Great. Thanks so much. :) What I am ultimately trying to do is to split text for multiple rows. The second row is "AZ" as the delimiter.
If it helps, the delimiter is the first two letters of the row. Maybe using the left function.
Book3
ABC
1TextWhat I like
2CZ DOG ER CZ DOG EE CZ CAT ER CZ CAT EE CZ SNAKE EE CZ SNAKE ER CZ HOUSE EE CZ HOUSE ERCZ DOG ER
3AZ DOG ER AZ DOG EE AZ CAT ER AZ CAT EE AZ SNAKE EE AZ SNAKE ER AZ HOUSE EE AZ HOUSE ERCZ DOG EE
4CZ CAT ER
5CZ CAT EE
6CZ SNAKE EE
7CZ SNAKE ER
8CZ HOUSE EE
9CZ HOUSE ER
10AZ DOG ER
11AZ DOG EE
12AZ CAT ER
13AZ CAT EE
14AZ SNAKE EE
15AZ SNAKE ER
16AZ HOUSE EE
17AZ HOUSE ER
Sheet2
Cell Formulas
RangeFormula
B2:B9B2=TEXTSPLIT(SUBSTITUTE(A2,"CZ ","|CZ "),,"|",1)
Dynamic array formulas.
 
Upvote 0
Are the delimiters always the first characters of the strings i.e. CZ and AZ?
 
Upvote 0
Yes, they will be the first two characters. This is a report with states for the first two letters of the row. There could be 10 rows of similar data.
 
Upvote 0
Try:
Book4
AB
1
2TextWhat I like
3CZ DOG ER CZ DOG EE CZ CAT ER CZ CAT EE CZ SNAKE EE CZ SNAKE ER CZ HOUSE EE CZ HOUSE ERCZ DOG ER
4AZ DOG ER AZ DOG EE AZ CAT ER AZ CAT EE AZ SNAKE EE AZ SNAKE ER AZ HOUSE EE AZ HOUSE ERCZ DOG EE
5CZ CAT ER
6CZ CAT EE
7CZ SNAKE EE
8CZ SNAKE ER
9CZ HOUSE EE
10CZ HOUSE ER
11AZ DOG ER
12AZ DOG EE
13AZ CAT ER
14AZ CAT EE
15AZ SNAKE EE
16AZ SNAKE ER
17AZ HOUSE EE
18AZ HOUSE ER
Sheet4
Cell Formulas
RangeFormula
B3:B18B3=DROP(REDUCE("",A3:A4,LAMBDA(x,y,LET(d,LEFT(y,3),VSTACK(x,d&TEXTSPLIT(y,,d,1))))),1)
Dynamic array formulas.
 
Upvote 0
Try.
Excel Formula:
=TEXTSPLIT(REDUCE("", A2:A3, LAMBDA(acc,x, acc & SUBSTITUTE(x, LEFT(x, 2), "|" & LEFT(x, 2)))),,"|",TRUE)
 
Upvote 0
Absolutely fantastic. Thank you so much to everyone. :) (y) These are powerful formulas. This will save me so much time. I got to look at learning more about the REDUCE function.
 
Last edited:
Upvote 0
Or try this.
Excel Formula:
=TEXTSPLIT(TEXTJOIN("",,SUBSTITUTE(A2:A3,LEFT(A2:A3,2),"|" & LEFT(A2:A3,2))),,"|",TRUE)
 
Upvote 0
Thanks so much Hong Ru for the last solution. This works great as well. (y) :)
 
Upvote 0

Forum statistics

Threads
1,226,771
Messages
6,192,926
Members
453,767
Latest member
922aloose

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