Search code examples
excelexcel-formula

Get the first and last number occuring in a (text) string in a cell


0 A B C
1 first number last number
2 Top1-5 1 5
3 Top5-10 5 10
4 Top11-15 11 15

In Column B I want to extract the first number occuring in the strings in Column A.
In Column C I want to extract the last number occurring in the strings in Column A.

I tried to apply solutions from this question but they did not work in my case.

Which formula do I need to get the expected results in Column B and Column C?


Solution

  • This formula accepts any lengths of the numbers.

    B20: =LET(perchar,MID(TEXTBEFORE(A20,"-"),SEQUENCE(1,LEN(TEXTBEFORE(A20,"-"))),1), TEXTJOIN("",TRUE,IF(ISNUMBER(--perchar),perchar,"")))

    C20: =TEXTAFTER(A20,"-")

    enter image description here