1

Sorry I'm a noob in excel and need help with this. Say I have the following text in my excel.

  1. D:/folder A/ folder B.1/text_01.txt
  2. D:/folder A/Folder C/ folder C.1/text_02.msg

I like to remove all the text from the right after the first occurrence "/" counting from the right.

So I would get the followings.

  1. D:/folder A/ folder B.1
  2. D:/folder A/Folder C/ folder C.1

3 Answers 3

1

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

=LEFT(A1,FIND("}}}",SUBSTITUTE(A1,"/","}}}",LEN(A1)-LEN(SUBSTITUTE(A1,"/","")))-1)
Sign up to request clarification or add additional context in comments.

Comments

0

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

enter image description here

1 Comment

Note, if you want to keep the slash / then simply remove the -1 from the code
0

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

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.