1

I have a CSV in which column A is populated with strings, such as:

ABCDE/FGHI/JKL/MNOPQR

I need to populate column C with everything after the last occurrence of the "/". In this example, it would have to be "MNOPQR".

Is there a function that could be used for this? "RIGHT" doesn't seem to do the trick. I don't know what the length of the substring will be in each row, so I definitely have to look for the "/".

Community
  • 1
  • 1
katharey
  • 23
  • 1
  • 1
  • 3

3 Answers3

2

If your text is in A4, put this in another cell:

=MID(A4,LEN(LEFT(A4,FIND(CHAR(1),SUBSTITUTE(A4,"/",CHAR(1),LEN(A4)-LEN(SUBSTITUTE(A4,"/",""))))))+1,LEN(A4)-LEN(LEFT(A4,FIND(CHAR(1),SUBSTITUTE(A4,"/",CHAR(1),LEN(A4)-LEN(SUBSTITUTE(A4,"/",""))))))+1)

I think that should work. Thanks to @Jerry for the main part, where it finds the last / in a string.

enter image description here

edit: Per @ScottCraner, this is shorter: =MID(A1,SEARCH("}}}",SUBSTITUTE(A1,"/","}}}",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))‌​))+1,LEN(A1))

Nimantha
  • 6,405
  • 6
  • 28
  • 69
BruceWayne
  • 22,923
  • 15
  • 65
  • 110
2

Here's a bit shorter formula to return the last delimited substring in a string.

=TRIM(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",99)),99))

Replace the delimiter with 99 spaces, then return the rightmost 99 characters. The leading characters must be spaces also, so TRIM gets rid of them.

Ron Rosenfeld
  • 53,870
  • 7
  • 28
  • 60
0

A simple formula approach using FilterXML might be:

    =FILTERXML("<items><i>" & SUBSTITUTE(A1,"/","</i><i>") & "</i></items>","//i[position()=last()]")

Profitting from the dynamic features of vers. 2019+ you can change the cell address to a range input, e.g. A1:A10 allowing output in a so called spill range.

VBA approach

As the VBA tag has been recently added to OP, an obvious VBA approach would be to split the string input and get the last array element via Ubound():

    Dim tmp As Variant
    tmp = Split("ABCDE/FGHI/JKL/MNOPQR", "/")
    Debug.print tmp(Ubound(tmp))     ' ~~> MNOPQR
T.M.
  • 9,436
  • 3
  • 33
  • 57