Extracting a filename from a path specification
The following formula returns the filename from a full path specification. For example, if cell A1
contains c:\files\excel\myfile.xlsx, the formula returns myfile.xlsx.
=MID(A1,FIND(“*”,SUBSTITUTE(A1,”\”,”*”,LEN(A1)-LEN(SUBSTITUTE(A1,”\”,””))))+1,LEN(A1))
This formula assumes that the system path separator is a backslash (\). It essentially returns all
the text following the last backslash character. If cell A1 doesn’t contain a backslash character,
the formula returns an error.
The following formula returns the filename from a full path specification. For example, if cell A1
contains c:\files\excel\myfile.xlsx, the formula returns myfile.xlsx.
=MID(A1,FIND(“*”,SUBSTITUTE(A1,”\”,”*”,LEN(A1)-LEN(SUBSTITUTE(A1,”\”,””))))+1,LEN(A1))
This formula assumes that the system path separator is a backslash (\). It essentially returns all
the text following the last backslash character. If cell A1 doesn’t contain a backslash character,
the formula returns an error.
No comments:
Post a Comment