• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Extracting text - is there a simpler, more elegant way to solve this problem?

blueguitar23

New Member
Hi all

I want to extract the word Gas from the text string "Walking Gazelle Gas-Water" - text in cell A15. I have a solution, which is:


=MID(A15,FIND(" ",A15,FIND(" ",A15)+1)+1,LEN(A15)-FIND(" ",A15,FIND(" ",A15)+1)-(LEN(A15)-LEN(RIGHT(A15,FIND("-",A15)))+1))


But I did wonder if anyone knew of a shorter, simpler way of solving the problem.


Thanks for reading


Stan
 
if your word to find always has "-" and always consist of 3 words, you can try below


=MID(A15,FIND("-",A15,1)-4,4)
 
Hi !


I prefer a two cells way to avoid gas-factory formulas …     For example :


cell G15 formula :   =REPLACE(A15,1,FIND(" ",A15,FIND(" ",A15)+1),"")


cell H15 formula :   =MID(G15,1,FIND("-",G15)-1)


 

For a unique cell formula in a shorter way,

nothing else than a VBA personal function like this one (to be inserted in a normal module) :

[pre]
Code:
Function ExtractLast(After As String, Before As String, Cel As String) As String
P = InStrRev(Cel, After)
If P Then E = InStr(P + 1, Cel, Before)
If E Then ExtractLast = Mid(Cel, P + 1, E - P - 1)
End Function
[/pre]

The cell formula is :   =ExtractLast(" ","-",A15)


 
 
Hi, blueguitar23!


If for extracting you mean removing you can use this:

=SUSTITUIR(A1;"Gas";"") -----> in english: =SUBSTITE(A1,"Gas","")


Regards!
 
Back
Top