extract info from between the first and *third* occurrence of a dash

edjusted

New Member
Joined
Oct 16, 2014
Messages
14
We're using this formula to extract info from between the first and third occurrence of a dash, but it relies on the extracted info being a fixed length:
=IF(K2="Other","Other",IF(LEN(A2)<12,MID(A2,FIND("-",A2)+1,LEN(A2)-4),IF(LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))>2,TRIM(MID(SUBSTITUTE(SUBSTITUTE(A2,"-",REPT(" ",255),3),"-",REPT(" ",255),1),255,255)),"")))

This works well because we used to have a fixed length between 1st and 3rd dash, but now the text is variable and we need a formula to work regardless of the length of the middle section.

Also, if there is no 3rd dash, we want to just extract the info from the first dash to the end of the string.


How do I convert this formula so it works regardless of the length of the text between the dashes?








 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
The second half of your current formula seems to do what you want:

=TRIM(MID(SUBSTITUTE(SUBSTITUTE(A2,"-",REPT(" ",255),3),"-",REPT(" ",255),1),255,255))

As long as the total length of the cell is under 255. Otherwise, raise 255 everywhere in the formula to some larger number, or even change it to LEN(A2)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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