Extract a Word from String Containing a Specific Character within Substring

前端 未结 2 1081
南方客
南方客 2021-01-16 10:46

In MS Excel I would like to use a formula to extract only the word from a cell that contains a specific character (\"=\") within the text.

A2: Dolly made me a homem

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-16 11:30

    I used 5 helper columns to do this; they could be collapsed into one very long forumula, but I prefer it this way (easier to track down source of any errors I think). Given the strings you have in A2; In B2 this finds location of "="

    =SEARCH("=",A2)  
    

    In C2 this finds the instance number of the " " preceeding the "="

    =B2-LEN(SUBSTITUTE(MID(A2,1,B2)," ",""))  
    

    In D2 this notes the location of that " "

    =SEARCH(CHAR(33),SUBSTITUTE(A2," ",CHAR(33),C2))  
    

    In E2 this locates the " " trailing the "=", or if the "=" appears in the final word in the cell it notes the full cell length +1

    =IFERROR(SEARCH(" ",A2,B2),LEN(A2)+1)  
    

    Using these values in F2 this pulls the string from the preceeding " " to the trailing " "

    =MID(A2,D2+1,E2-D2-1)
    

提交回复
热议问题