Remove and replace parts of text string in cell

rinnue

Board Regular
Joined
Feb 28, 2003
Messages
142
Long story short, my large playlist in my music data base got messed up during a sync.
I have a good m3u file but I need to change the path of each file to match the database locations.

So I would love to use a formula or vb to do the following:
Remove the first 3 characters after the third ""
Replace the first " - " with "" and ignore the second " - "
Yes there are spaces either side of the dash.

Essentially, I need this
F:\Music\AC-DC - Back In Black\08 AC-DC - Have A Drink On Me.mp3

To end up like this
F:\Music\AC-DC\Back In Black\AC-DC - Have A Drink On Me.mp3

I would do it manually...and may end up doing it manually, but there are ~1800 rows....so I would rather not.

Thanks for any help.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Long story short, my large playlist in my music data base got messed up during a sync.
I have a good m3u file but I need to change the path of each file to match the database locations.

So I would love to use a formula or vb to do the following:
Remove the first 3 characters after the third ""
Replace the first " - " with "" and ignore the second " - "
Yes there are spaces either side of the dash.

Essentially, I need this
F:\Music\AC-DC - Back In Black\08 AC-DC - Have A Drink On Me.mp3

To end up like this
F:\Music\AC-DC\Back In Black\AC-DC - Have A Drink On Me.mp3

I would do it manually...and may end up doing it manually, but there are ~1800 rows....so I would rather not.

Thanks for any help.



Hello!

The description you've given and the example shown don't match...


Remove the first three characters after the third ""

That is ok.



Replace the first " - " with "" and ignore the second


The example given actually replaces the first " - " with "\" (a backslash character)


F:\Music\AC-DC - Back In Black\08 AC-DC - Have A Drink On Me.mp3

F:\Music\AC-DC\Back In Black\AC-DC - Have A Drink On Me.mp3


Assuming this is what you wanted, and the data is in cell A1

Put in cell B1:


=REPLACE(LEFT(A1,FIND("#",SUBSTITUTE(A1,"","#",3))) & RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"","#",3))-3),SEARCH(" - ",LEFT(A1,FIND("#",SUBSTITUTE(A1,"","#",3))) & RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"","#",3))-3)),3,"")


and copy down.


Excel 2010
AB
F:\Music\AC-DC - Back In Black\08 AC-DC - Have A Drink On Me.mp3F:\Music\AC-DC\Back In Black\AC-DC - Have A Drink On Me.mp3

<tbody>
[TD="align: center"]1[/TD]

</tbody>


[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]B1[/TH]
[TD="align: left"]=REPLACE(LEFT(A1,FIND("#",SUBSTITUTE(A1,"","#",3))) & RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"","#",3))-3),SEARCH(" - ",LEFT(A1,FIND("#",SUBSTITUTE(A1,"","#",3))) & RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"","#",3))-3)),3,"")[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]









Just in case you didn't want that backlash character to replace the first occurrence of " - "

Put whatever you want to place it in cell C1 (and copy this down as well, or change to an Absolute cell reference)



Excel 2010
ABC
F:\Music\AC-DC - Back In Black\08 AC-DC - Have A Drink On Me.mp3F:\Music\AC-DC@Back In Black\AC-DC - Have A Drink On Me.mp3@

<tbody>
[TD="align: center"]1[/TD]

</tbody>


[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR="bgcolor: #DAE7F5"]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH="bgcolor: #DAE7F5"]B1[/TH]
[TD="align: left"]=REPLACE(LEFT(A1,FIND("#",SUBSTITUTE(A1,"","#",3))) & RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"","#",3))-3),SEARCH(" - ",LEFT(A1,FIND("#",SUBSTITUTE(A1,"","#",3))) & RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"","#",3))-3)),3,C1)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
Thanks for your reply.
That is so odd. The slash was removed in the preview the first time. I went back and fixed it. Then previewed again. It was there so I posted, but it seems it got removed again.
Anyway, you are correct I want what you have shown in the first scenario.
I just need this
F:\Music\AC-DC - Back In Black\08 AC-DC - Have A Drink On Me.mp3

To end up like this.
F:\Music\AC-DC\Back In Black\AC-DC - Have A Drink On Me.mp3

All my data resides in the A column. A1-A1776
I copied your formula to B1 then I copied it down to B1776

Unfortunately I am getting a #Value ! errror
 
Upvote 0
Curious, in your formula should the "#" be a "slash" ?

I also tried the second formula and put my slash in C1. I still get the #Value ! error
 
Upvote 0
Oh.. !

Never mind.. found out what the problem was.


You know you mentioned it was odd because you'd put the backslash character in and it was there in the preview...

For some reason.. the forum takes out the backslash character.

And.. it's done it with the FORMULA!!! Gah!



To stop it from doing it again, here's the formula:

=REPLACE(LEFT(A1,FIND("#",SUBSTITUTE(A1,"[BACKSLASH]","#",3))) & RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"[BACKSLASH]","#",3))-3),SEARCH(" - ",LEFT(A1,FIND("#",SUBSTITUTE(A1,"[BACKSLASH]","#",3))) & RIGHT(A1,LEN(A1)-FIND("#",SUBSTITUTE(A1,"[BACKSLASH]","#",3))-3)),3,"[BACKSLASH]")



Use Find and Replace (in maybe notepad) and replace [BACKSLASH] with the actual backslash symbol.


Should look like this:

zjv0x0.jpg
 
Last edited:
Upvote 0
Yes sir. That worked nicely.
I've been messing around with this on and off for 3 months now.
Thanks for you help! It will be soooo nice to have my playlist back!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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