Extract SubString from Middle of string

StevenPMoffat
StevenPMoffat used Ask the Experts™
on
I need a simple function that will extract the substring that starts at position 5 and includes up to the first "-".

For Instance:
With
ABC-System1-012345960    I Get System1
ABC-A-34509   I get A.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
How about this:

=Mid(A1, 5, Find("-", A1, 6)-5)
Commented:
Actually, just to ensure that the second dash exists, I usually update it like this:

=MID(A1, 5, FIND("-", A1 & "-",5)-5)

Commented:
If the location of the first dash will change, it needs to get a tiny bit more complex:

Basically replace each 5 with a find:

=MID(A1, FIND("-",A1)+1, FIND("-", A1 & "-",FIND("-",A1)+1)-FIND("-",A1)-1)

Commented:
here you go!
=MID(A1,5,FIND("-",A1,5)-5)
---Assuming A1 is your value


Author

Commented:
Thank You

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial