Solved

Revising TRIM formula to also remove file extension

Posted on 2014-03-17
4
1,071 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 50

Expert Comment

by:barry houdini
ID: 39935283
Try this version

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

regards, barry
0
 

Author Comment

by:Andreamary
ID: 39938203
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
ID: 39938433
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
ID: 39940500
Perfect! I'm using Excel 2010, so the Excel 2007 version did the trick. Thanks so much...
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

688 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