0

I have various strings (formatted as text) that have a similar syntax in column F. Eg:

1t ttn TEST FAILED (9-5 passOne, 21-7 & 877-12 passTwo)

I want to extract the numbers within the brackets into separate cells. There may be anywhere between 1 and 5 different numbers.

The numbers will always contain a dash (-) somewhere in the middle and may have up to 3 digits either side of the dash.

Is this possible? I've been through previous questions and can't find anything that answers this.

Edit to show entered JvdV formula:

enter image description here

Robsmith
  • 339
  • 1
  • 8

1 Answers1

3

With Excel 2016:

enter image description here

Formula in B1:

=SUBSTITUTE(FILTERXML("<t><s>`"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(REPLACE($A1,1,FIND("(",$A1),""),")",""),"&","&")," ","</s><s>`")&"</s></t>","//s[contains(., '-')][translate(., '`-','')*0=0]["&COLUMN(A1)&"]"),"`","")

Confirm through CtrlShiftEnter

Drag right, and down for all lines of data.


This assumed:

  • Substring of interest (between paranthesis) is always at the end.
  • Numbers with the hyphen as a delimiter may occur outside this substring and are not wanted in our results.

The trick here is to first sanitize the string and find the opening-paranthesis and remove everything prior to that using REPLACE(). Then, just SUBSTITUTE() the closing-paranthesis. The remainder can be split on spaces using FILTERXML(). To prevent errors and unwanted results I subsituted the ampersand and included accent graves to prevent Excel to recognize these substrings as dates. For more insight on the used xpath and the workings of FILTERXML() I'd like to refer you to this.

JvdV
  • 70,606
  • 8
  • 39
  • 70