Forum Discussion

meierli's avatar
meierli
Copper Contributor
Jan 27, 2023
Solved

Extract number various length from middle of string

I would like to extract the number between TRN*1* and the next *. Currently i have a formula that is based off the same characters (*) but recently my data set changed so that I need to bring in addi...
  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Jan 27, 2023

    meierli Well, this is becoming increasingly ugly 🙂

    You could use SUBSTITUTE to replace two consecutive asterisks by one. Just replace A1 by SUBSTITUTE(A1,"**","*") for every occasion. But the repetition isn't very elegant, even though it works.

    =LEFT(RIGHT(SUBSTITUTE(A1,"**","*"),LEN(SUBSTITUTE(A1,"**","*"))-(FIND("TRN*1*",SUBSTITUTE(A1,"**","*"))+5)),FIND("*",RIGHT(SUBSTITUTE(A1,"**","*"),LEN(SUBSTITUTE(A1,"**","*"))-(FIND("TRN*1*",SUBSTITUTE(A1,"**","*"))+5)))-1)

    If you have a large data set and other inconsistencies turn up, perhaps better to look into Power Query and deal with them there. Much cleaner than working with regular formulas and trying to capture them with nested IF statements.

Resources