Extract A String Between Two Characters

theaudioguy

New Member
Joined
Jan 27, 2010
Messages
27
I'm stuck. I need a formula to extract data from between two characters.

For Example, In A1 I have this: COMP_PROG_v1_ABCD_01

I want to extract the value between the 3rd and 4th "_"'s. The number of "_"'s will be consistent but not the # of characters between them. My brain is tired of thinking. Thanks.
 
please can you assist me as well....

Trying to get a number out of a file name - "A4U-20MAY14-CI-004-W-10-A-N.mp4"
I need to get the 10 out of the file name - the 2 dashes from right to left are constant the number (10 in this case) can go up to 4 digits but will always be behind a dash.

TIA
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Give this formula a try...

=TRIM(LEFT(RIGHT(SUBSTITUTE("-"&A1,"-",REPT(" ",300)),900),300))

The above formula returns numbers as text, if you need the number to be a real number, just add 0...

=0+TRIM(LEFT(RIGHT(SUBSTITUTE("-"&A1,"-",REPT(" ",300)),900),300))
 
Upvote 0
Thanks a mill - this was my attempt - LOL

=MID(A3,FIND("-",$A$3,FIND("-",$A$3,FIND("-",$A$3,FIND("-",$A$3,FIND("-",A3)+1)+1)+1)+1)+1,(FIND("-",$A$3,FIND("-",$A$3,FIND("-",$A$3,FIND("-",$A$3,FIND("-",$A$3,FIND("-",A3)+1)+1)+1)+1)+1)-FIND("-",$A$3,FIND("-",$A$3,FIND("-",$A$3,FIND("-",$A$3,FIND("-",A3)+1)+1)+1)+1)-1))
 
Upvote 0
Give this formula a try...

=TRIM(LEFT(RIGHT(SUBSTITUTE("-"&A1,"-",REPT(" ",300)),900),300))

The above formula returns numbers as text, if you need the number to be a real number, just add 0...

=0+TRIM(LEFT(RIGHT(SUBSTITUTE("-"&A1,"-",REPT(" ",300)),900),300))
Minor saving but can't the blue bit be left out?
 
Upvote 0
or a UDF ?

in A1: "A4U-20MAY14-CI-004-W-10-A-N.mp4"

In B1: =F_snb(A1)

In a macromodule:

Code:
Function F_snb(c00)
   F_snb = Split(c00, "-")(5)
End Function

 
Upvote 0
or a UDF ?

in A1: "A4U-20MAY14-CI-004-W-10-A-N.mp4"

In B1: =F_snb(A1)

In a macromodule:

Code:
Function F_snb(c00)
   F_snb = Split(c00, "-")(5)
End Function
I don't know why, but I do not see your complete message in your original posting... the part in red is missing and the part in blue appears after your code, not before it.:confused:

Anyway, my reason for responding is to note the OP said "the 2 dashes from right to left are constant" which suggested to me that the number of dashes prior to it may not be fixed at 5 which, if that is the case, your code would need to be modified to count the number of dashes total and subtract two from it. With that said, I am not sure I would go with a UDF solution when such a relatively simple formula is available.

EDIT NOTE: Ignore the first paragraph above... now I see the text I said was missing.:confused:
 
Upvote 0
You mean ?

Code:
Function F_snb(c00)
   sn=split(c00,"-")
    F_snb = sn(ubound(sn)-2)
 End Function
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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