TRIM-MID-SUBSTITUTE TO KEEP CHARACTERS IN THE 2ND DELIMINATED COLUMN

JuicyMusic

Board Regular
Joined
Jun 13, 2020
Messages
210
Office Version
  1. 365
Platform
  1. Windows
Hi Guru's, I have a formula that I found on another post from FLUFF here on MrExcel. I would like help adjusting it. I DOWNLOADED XL2BB SO PLEASE TELL ME IF IT IS WORKING.

Here is the formula I am needing adjustment to:
Excel Formula:
=TRIM(MID(SUBSTITUTE("*"&$I8,"*",REPT(" ",100)),COLUMNS($J8:J8)*100,100))

I would like the characters to remain in the 2nd column that is deliminated. If there is only an "*" in the original data, then column 2 should be blank.

Here is the original data I am working with - the next 2 columns are showing the results I would like to see:

DESIRED RESULTS - col 1DESIRED RESULTS - col 2
ORIGINAL DATA TO TEXT DELIMINATECITY NAMES (in new 1st column)CITY NOTE (in new 2nd column)
Adelanto*Adelanto
Alberhill (Lake Elsinore*)Alberhill(Lake Elsinore*)
Alta Loma (Rancho Cucamonga*)Alta Loma(Rancho Cucamonga*)
Alviso (San Jose*)Alviso(San Jose*)
Amargosa (Death Valley)Amargosa(Death Valley)
Bay Point (formally West Pittsburg)Bay Point(formally West Pittsburg)
Beverly Hills*Beverly Hills
Big Bear Lake*Big Bear Lake
Coto De CazaCoto De Caza
Crest ParkCrest Park
DaggettDaggett
Davis* (U.C. Davis campus rate is 7.25%)Davis(U.C. Davis campus rate is 7.25%)
Del SurDel Sur
Dos RiosDos Rios
Santa Barbara* (U.C. Santa Barbara campus rate is 7.75%)Santa Barbara(U.C. Santa Barbara campus rate is 7.75%)

Thank you everyone,
Juicy
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Looking at your sample, I think you're trying to overcomplicate things. See if this works.
I can't test it at the moment, hopefully no typos in the formulas.
1st column
Excel Formula:
=IFERROR(TRIM(SUBSTITUTE(LEFT(I8,FIND("(",I8)-1),"*","")),I8)
2nd column
Excel Formula:
=IFERROR(MID(I8,FIND("(",I8),LEN(I8)),"")
 
Upvote 0
I DOWNLOADED XL2BB SO PLEASE TELL ME IF IT IS WORKING.
It is not working. You need to follow the steps here carefully.

I can't test it at the moment, hopefully no typos in the formulas.
Not a typo but I think that you have the SUBSTITUTE in the first one in the wrong place since the desired results shown have no asterisks in the first column.
Excel Formula:
=SUBSTITUTE(IFERROR(TRIM(LEFT(I8,FIND("(",I8)-1)),I8),"*","")

@JuicyMusic
A couple of alternatives to consider also

22 04 23.xlsm
IJKL
7ORIGINAL DATA TO TEXT DELIMINATECITY NAMESCITY NOTE
8Adelanto*Adelanto 
9Alberhill (Lake Elsinore*)Alberhill(Lake Elsinore*)
10Alta Loma (Rancho Cucamonga*)Alta Loma(Rancho Cucamonga*)
11Alviso (San Jose*)Alviso(San Jose*)
12Amargosa (Death Valley)Amargosa(Death Valley)
13Bay Point (formally West Pittsburg)Bay Point(formally West Pittsburg)
14Beverly Hills*Beverly Hills 
15Big Bear Lake*Big Bear Lake 
16Coto De CazaCoto De Caza 
17Crest ParkCrest Park 
18DaggettDaggett 
19Davis* (U.C. Davis campus rate is 7.25%)Davis(U.C. Davis campus rate is 7.25%)
20Del SurDel Sur 
21Dos RiosDos Rios 
22Santa Barbara* (U.C. Santa Barbara campus rate is 7.75%)Santa Barbara(U.C. Santa Barbara campus rate is 7.75%)
Split Columns
Cell Formulas
RangeFormula
K8:K22K8=TRIM(SUBSTITUTE(SUBSTITUTE(I8,L8,""),"*",""))
L8:L22L8=MID(I8,FIND("(",I8&"("),LEN(I8))
 
Upvote 0
Solution
A couple of alternatives to consider also
Here is a possible alternative for cell K8 (I have no idea if it might be more efficient or not)...

=LEFT(I8,MIN(FIND({"*","("," ("},I8&"* (")-1))

If there will always be a space in front of the opening parenthesis (when present), then this slightly shorter formula can be used instead...

=LEFT(I8,MIN(FIND({"*"," ("},I8&"* (")-1))
 
Last edited:
Upvote 0
Rick, what did you do with that quote?!?! :eek:
 
Upvote 0
Here is a possible alternative for cell K8 (I have no idea if it might be more efficient or not)...

=LEFT(I8,MIN(FIND({"*","("," ("},I8&"* (")-1))

If there will always be a space in front of the opening parenthesis (when present), then this slightly shorter formula can be used instead...

=LEFT(I8,MIN(FIND({"*"," ("},I8&"* (")-1))
Hello Rick, This is data from the city and they don't seem to have a standard way of adding spaces and/or characters. Your suggestion will work perfectly for another project I'm working on.

I did use your first suggestion for column K:
Excel Formula:
=LEFT(I8,MIN(FIND({"*","("," ("},I8&"* (")-1))

And I used Peter's 2nd formula for column L:
Excel Formula:
=MID(I8,FIND("(",I8&"("),LEN(I8))

It looks like this way K and L are not dependent on each other. Thank you for explaining what my original formula was doing. I understand it now.
SOLVED by Rick and Peter

Thank you so much!
Juicy
 
Last edited:
Upvote 0
Glad we could help to get something that you are satisfied with. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,777
Members
449,187
Latest member
hermansoa

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