Separate string based on another cells value and another parameter

chive90

Board Regular
Joined
May 3, 2023
Messages
56
Office Version
  1. 2016
Hello

In D2 I have a URL string.

Example: http://test/example/blah/name/aaa/bbb/ccc/document.xls

"name/" is also present in C2

In E2, I require the part of the string highlighted in bold (i.e. aaa/bbb/ccc/)

Is there a formula that I can use to only pick up the text in D2 after what the value is in C2 (in this case "name/") and to also not pick up anything after the final / (in this case "document.xls")

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi chive90,

This should work, thanks!

=TEXTBEFORE(TEXTAFTER(D2,C2),"/",3)&"/"

Logic as follows: Text after C2 -> then Text before 3rd instance of /

Edit: Added a &"/" as you need that last /


Production Template.xlsm
CDE
2name/ http://test/example/blah/name/aaa/bbb/ccc/document.xlsaaa/bbb/ccc
Sheet2
Cell Formulas
RangeFormula
E2E2=TEXTBEFORE(TEXTAFTER(D2,C2),"/",3)
 
Upvote 0
Hi chive90,

This should work, thanks!

=TEXTBEFORE(TEXTAFTER(D2,C2),"/",3)&"/"

Logic as follows: Text after C2 -> then Text before 3rd instance of /

Edit: Added a &"/" as you need that last /


Production Template.xlsm
CDE
2name/ http://test/example/blah/name/aaa/bbb/ccc/document.xlsaaa/bbb/ccc
Sheet2
Cell Formulas
RangeFormula
E2E2=TEXTBEFORE(TEXTAFTER(D2,C2),"/",3)

Hey, thanks for replying. I should have probably stated that I am using Excel 2016 and I don't believe the TEXTBEFORE or TEXTAFTER functions work in 2016?

Is there any alternative that can be used which will achieve the same result?

Thank you
 
Upvote 0
How about
Fluff.xlsm
CDE
1
2name/ http://test/example/blah/name/aaa/bbb/ccc/document.xlsaaa/bbb/ccc
Master
Cell Formulas
RangeFormula
E2E2=REPLACE(LEFT(D2,FIND("^",SUBSTITUTE(D2,"/","^",LEN(D2)-LEN(SUBSTITUTE(D2,"/",""))))-1),1,SEARCH(C2,D2)+LEN(C2)-1,"")
 
Upvote 1
Solution

Forum statistics

Threads
1,223,754
Messages
6,174,311
Members
452,554
Latest member
Louis1225

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