Get file extension formula

G

garle

Given file names that appear in a worksheet, and contain extensions of
uncertain length (e.g. .txt, .properties, .doc, etc), what's a good
formula to return the extension string itself?

Would want this to fail gracefully if there is no extension and handle
cases where "." appears elsewhere in the file name. That is, return the
last string delimited by "."

Thanks in advance!
 
N

Niek Otten

=RIGHT(SUBSTITUTE(A1,".","~",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))),LEN(SUBSTITUTE(A1,".","~",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))-FIND("~",SUBSTITUTE(A1,".","~",LEN(A1)-LEN(SUBSTITUTE(A1,".","")))))

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

| Given file names that appear in a worksheet, and contain extensions of
| uncertain length (e.g. .txt, .properties, .doc, etc), what's a good
| formula to return the extension string itself?
|
| Would want this to fail gracefully if there is no extension and handle
| cases where "." appears elsewhere in the file name. That is, return the
| last string delimited by "."
|
| Thanks in advance!
|
 
B

Bernie Deitrick

To fail gracefully:

=IF(ISERROR(MID(A1,FIND("#",SUBSTITUTE(A1,".","#",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))),1)+1,200)),"",MID(A1,FIND("#",SUBSTITUTE(A1,".","#",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))),1)+1,200))

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top