How to remove all text from right after certain characters in excel

余生颓废 提交于 2019-12-02 05:49:41

Use LEFT() with FIND and SUBSTITUTE to find the last /

=LEFT(A1,FIND("}}}",SUBSTITUTE(A1,"/","}}}",LEN(A1)-LEN(SUBSTITUTE(A1,"/","")))-1)

If you don't mind a bit of , then InStrRev was almost tailor made for cases like these:

Public Function Remove_After(ByVal what As String, ByVal where As Range) As String
    Remove_After = Left(where, InStrRev(where, what) - 1)
End Function

If you have Excel 2016+ with the TEXTJOIN function, you can use this array formula:

=TEXTJOIN("/",TRUE,FILTERXML("<t><s>" & SUBSTITUTE(A1,"/","</s><s>")& "</s></t>","//s[position()<last()]"))

Since this is an array formula, you need to "confirm" it by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!