Efficient Formula to Extract Text Between Second and Third Hyphen in Excel 2021

irfman

New Member
Joined
Jan 1, 2019
Messages
19
Office Version
  1. 2021
Hi,

I have a large dataset stored as string values in Column A. I need to extract the text that appears immediately after the second hyphen (-) and before the third hyphen (-).

Currently, I am using the following formula:
=MID(A2, FIND(CHAR(1), SUBSTITUTE(A2, "-", CHAR(1), 2)) + 1, FIND(CHAR(1), SUBSTITUTE(A2, "-", CHAR(1), 3)) - FIND(CHAR(1), SUBSTITUTE(A2, "-", CHAR(1), 2)) - 1)

However, this formula is lengthy, complicated, and not efficient for a large dataset.

I am using Excel 2021. Are there any simpler and more efficient formulas to achieve the same result?

I appreciate your usual support and assistance.

1742729042964.png
 
Cheers. Glad you got something useful. Thanks for the follow-up. :)
 
Upvote 0
Excel Formula:
=MID(A2:A19,1+FIND("|",SUBSTITUTE(A2:A19,"-","|",2)),FIND("|",SUBSTITUTE(A2:A19,"-","|",3))-FIND("|",SUBSTITUTE(A2:A19,"-","|",2))-1)
 
Upvote 0
Just for fun:

=FILTERXML("<k><m>,&SUBSTITUTE(A2,"-","</m><m>")&"</m></k>","//m[3]")
That isn't a valid formula. Presumably you meant this?
Excel Formula:
=FILTERXML("<k><m>"&SUBSTITUTE(A2,"-","</m><m>")&"</m></k>","//m[3]")

.. but that is by far the slowest, about 14 times as long as the OP's original formula on my machine.

irfman.xlsm
JKLMNOPQ
1Post 1Post 2Post 3Post 3bPost 4Post 9Post 14
2Time (secs) to recalculate 10,000 rows0.06240.044680.043840.034870.03720.027350.87403
3Rank6542317
Sheet1
Cell Formulas
RangeFormula
K3:Q3K3=RANK(K2,$K2:$Q2,1)
 
Upvote 0

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