Extract text from string

dawsman

Board Regular
Joined
Jul 20, 2010
Messages
55
Some excel wizardry required please.

In cell B1 i have the follwoing data <style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>https://example.ca/?utm_source=random1&utm_medium=random2&utm_campaign=random3&utm_term=random4

I am looking to extract the randomx text only, so random1 into b2, random2 into b3, random3 into b4 and random4 into b5

Is there a way of doing his, i have searched the web but haven't seen something appropriate.

Thanks!
 

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.
In B2:
=TRIM(LEFT(SUBSTITUTE(TRIM(MID(SUBSTITUTE($B$1,"=",REPT(" ",100)),100*ROWS($B$1:B1),100)),"&",REPT(" ",100)),100))
Copy down to B4


Excel 2010
B
1https://example.ca/?utm_source=random1&utm_medium=random2&utm_campaign=random3&utm_term=random4
2random1
3random2
4random3
5random4
Sheet1
Cell Formulas
RangeFormula
B2=TRIM(LEFT(SUBSTITUTE(TRIM(MID(SUBSTITUTE($B$1,"=",REPT(" ",100)),100*ROWS($B$1:B1),100)),"&",REPT(" ",100)),100))
B3=TRIM(LEFT(SUBSTITUTE(TRIM(MID(SUBSTITUTE($B$1,"=",REPT(" ",100)),100*ROWS($B$1:B2),100)),"&",REPT(" ",100)),100))
B4=TRIM(LEFT(SUBSTITUTE(TRIM(MID(SUBSTITUTE($B$1,"=",REPT(" ",100)),100*ROWS($B$1:B3),100)),"&",REPT(" ",100)),100))
B5=TRIM(LEFT(SUBSTITUTE(TRIM(MID(SUBSTITUTE($B$1,"=",REPT(" ",100)),100*ROWS($B$1:B4),100)),"&",REPT(" ",100)),100))
 
Upvote 0
This works great apart from the last formula which is cutting off early so the full string is not showing e.g. rando instead on random4
 
Upvote 0
It didn't do that with your sample text, can you provide sample data of where it didn't work?
 
Upvote 0
Here an example text https://xxxxxxx.xx/?utm_source=xxxxxxxx&utm_medium=xxx&utm_campaign=xxxxxxxxxxxxxxxxxx&utm_term=xx_generic_traffic

returned correct apart from last formula which returned xx_gene and missed the remaining 11 characters

we also have https://www.xxxxxxx.xx/search/boarding/?utm_source=xxxxxxxx&utm_medium=xxx[FONT=Inconsolata, monospace, arial, sans, sans-serif]&utm_campaign=[/FONT]xx_remarketing_all_visitors[FONT=Inconsolata, monospace, arial, sans, sans-serif]&utm_term=[/FONT]xx_remarketing_all_visitors

[FONT=Inconsolata, monospace, arial, sans, sans-serif]returned correctly for formulas 1 & 2 but 3 returned [/FONT]xx_remarketing instead of xx_remarketing_all_visitors and formula 4 returned_all_visitors

Hope that all make sense, thanks.
 
Upvote 0
=trim(left(substitute(trim(mid(substitute($b$1,"=",rept(" ",255)),255*rows($b$1:b1),255)),"&",rept(" ",255)),255))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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