Solved

Revising TRIM formula to also remove file extension

Posted on 2014-03-17
4
979 Views
Last Modified: 2014-03-19
I am currently using the following formula to extract the filename from a file path:

Filepath:
C:\Program Files\xxxx\zzzz\tttt\iiiiiiii\ooooo\wwwwww\YYBG-POP-7E.ai

Formula:
=TRIM(RIGHT(SUBSTITUTE(A2,"\",REPT(" ",LEN(A2))),LEN(A2)))

Results:
YYBG-POP-7E.ai
YOBP-QRT-4G.doc

I would like to revise the formula so it also removes the file extensions, which are either 2 or 3 character extensions, so that the results would be:

YYBG-POP-7E
YOBP-QRT-4G

Thanks!
Andrea
0
Comment
Question by:Andreamary
  • 2
  • 2
4 Comments
 
LVL 50

Expert Comment

by:barry houdini
Comment Utility
Try this version

=TRIM(RIGHT(SUBSTITUTE(LEFT(A2,FIND(".",A2)-1),"\",REPT(" ",LEN(A2))),LEN(A2)))

regards, barry
0
 

Author Comment

by:Andreamary
Comment Utility
Hi Barry,

It does the trick! The only tweak, if possible, is to hide the #VALUE if the cell in Column A is blank. Is that feasible?

Thanks,
Andrea
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
Comment Utility
Assuming you are using Excel 2007 or later you can just wrap the formula in IFERROR like this:

=IFERROR(TRIM(RIGHT(SUBSTITUTE(LEFT(A2,FIND(".",A2)-1),"\",REPT(" ",LEN(A2))),LEN(A2))),"")

that will return a blank instead of an error.

In earlier versions you could use a simple IF like

=IF(A2="","",TRIM(RIGHT(SUBSTITUTE(LEFT(A2,FIND(".",A2)-1),"\",REPT(" ",LEN(A2))),LEN(A2))))

That specifically returns a blank if A2 is blank

regards, barry
0
 

Author Closing Comment

by:Andreamary
Comment Utility
Perfect! I'm using Excel 2010, so the Excel 2007 version did the trick. Thanks so much...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Lately there has been a variety of news related to U.S. employment.  Stories about worker productivity, automobile and airline unions, low employment and foreign laborers have frequented the news.  Each story has good and bad attributes we might arg…
As freelancing is becoming more and more common in the tech industry, certain obstacles are proving to be a challenge to those who are used to more traditional, structured employment. This article is meant to help identify such obstacles and offer a…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now