Formula to result text between last two 'dash' ticks

Dojorgen

Board Regular
Joined
Mar 1, 2018
Messages
59
Hey guys,

always get me great feedback I have:

Cell C2:
/123K/XXX0-A/XXXX0-135-A0.job

I was looking for a formula that would return the value 135 in this example.

It will always be between the last two dashes in the cell.

Any suggestions would be much appreciated:)
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try

Code:
=TRIM(MID(SUBSTITUTE(C5,"-",REPT(" ",100)),200,100))
 
Upvote 0
You can always try Flash Fill... Enter manually the 135 in a cell in the same row, like D2, then press Ctrl/E to have Flash Fill use the patterning to do the rest in column C.

I did find a formula solution but it was 50 characters!
 
Upvote 0
Sorry should have given you all examples:
/XXXX0/XXXX0-330-B0

Is there something i can use for both?
 
Upvote 0
Hi,

Another way, in case you have varying length or text containing varying numbers of "hyphens".

D2 formula converts results to Real Numbers.
E2 formula results in Text.


Book1
CDE
1NumericText
2/123K/XXX0-A/XXXX0-135-A0.job135135
3123K/XXX0-A/XXXX0-B/XXXXX0-C/X0-136-XX.job136136
4/XXXX0/XXXX0-330-B0330330
Sheet466
Cell Formulas
RangeFormula
D2=MID(SUBSTITUTE(C2,"-",REPT(" ",99)),(LEN(C2)-LEN(SUBSTITUTE(C2,"-",""))-1)*99,99)+0
E2=TRIM(MID(SUBSTITUTE(C2,"-",REPT(" ",99)),(LEN(C2)-LEN(SUBSTITUTE(C2,"-",""))-1)*99,99))


EDIT: included your latest sample above, these formulas will work for ANY length text string.
 
Last edited:
Upvote 0
Try
Code:
=TRIM(LEFT(RIGHT(SUBSTITUTE(C5,"-",REPT(" ",100)),200),100))
 
Upvote 0
Hey Michael, just realized I made it more complicated than it needed to be...:)

Just in case OP wants results numeric, using your formula above:

=LEFT(RIGHT(SUBSTITUTE(C2,"-",REPT(" ",100)),200),100)+0
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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