Created
October 29, 2015 22:40
-
-
Save dznz/64a34466f44d1a335e75 to your computer and use it in GitHub Desktop.
Extract the filename from a path in Excel or Google spreadsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=TRIM(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",100)),99)) |
Clever! But does not work if the filename has more than 100 characters. You could use:
=TRIM(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",LEN(A1))),LEN(A1)-1))
Thanks for the tip. Also, you can trim the file extension with this:
=TRIM(RIGHT(SUBSTITUTE(Left(A1, Find(".",A1)-1),"/",REPT(" ",100)),99))
riffing on @eiannone's response:
=IFERROR(IF(SEARCH("/",A1,1), TRIM(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",LEN(A1))),LEN(A1)-1))), A1)
Wrapping the TRIM
in a conditional that looks for the /
character - otherwise the first character gets trimmed improperly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you