Extracting Strings

ike92

New Member
Joined
Mar 26, 2015
Messages
6
Hey Excel friends,

I cannot seem to figure out how to extract a string between two characters. I need to extract the Department, which is found in the section before gmail.com. I've been trying different combos of find(), len(), substitute(), but can't seem to get it correct!

Here are a couple of the strings:

THP80615/Computers/Spanish Publishing/gmail.com
THP80615/Desktops/Win7/Information Systems/gmail.com
THP80615/Foundation/President/gmail.com
THP80615/Computers/Operations/gmail.com
THP80615/Laptops/Win7/Computers/Information Systems/gmail.com
THP80615/Computers/Metering Stations/Shipping/Distribution/gmail.com

Thank you for your help in advance!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Give this formula a try...

=TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",300)),600),300))
 
Upvote 0
try:

Book1
A
1THP80615/Computers/Spanish Publishing/gmail.com
2THP80615/Desktops/Win7/Information Systems/gmail.com
3THP80615/Foundation/President/gmail.com
4THP80615/Computers/Operations/gmail.com
5THP80615/Laptops/Win7/Computers/Information Systems/gmail.com
6THP80615/Computers/Metering Stations/Shipping/Distribution/gmail.com
7
8
9Spanish Publishing
10Information Systems
11President
12Operations
13Information Systems
14Distribution
Foglio3
Cell Formulas
RangeFormula
A9=TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",100)),200),100))
 
Last edited:
Upvote 0
Thanks so much Mr. Rothstein! It works! I really appreciate your help and have a great day!!
 
Upvote 0
Hey Mr. Rothstein, could you explain to me your function?
=TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",300)),600),300))

I really want to understand this in order to emulate it in the future!

Thanks!!
 
Upvote 0
Hey Mr. Rothstein, could you explain to me your function?
=TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",300)),600),300))

I really want to understand this in order to emulate it in the future!
The SUBSTITUTE function replaces all slashes with 300 blank spaces... this means that every item between slashes can be found within its own 300 character chunk of the substituted text surrounded by spaces. Now, there is some theoretical adjustment that needs to be make for the length of each item between the slashes, but if the number of spaces is sufficiently larger than any one of these individual lengths, then they overwhelm the need for any adjustments. So, since you wanted the second item from the left, we use the RIGHT function to grab 600 (2 times the number of spaces that was added) characters from the right... in there will be the next-to-last and last items (separated by 300 spaces). We use the LEFT function to grab the leftmost 300 characters from that 600 character chunk... it will only contain the next-to-last item surrounded by spaces... we use the TRIM function to get rid of them.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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