Formula-Cell Contain File Extension Without File Path

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
794
Thanks for looking at my post as always.

I have the following formula in a cell that displays the file name.
=LEFT(CELL("filename"),FIND("]",CELL("filename"))-1)

THe problem I have with this is I need it to show only the filename. It shows the file path also. Is there away to edit the formula so it only shows the name?

Thanks
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

edmitchell

Board Regular
Joined
Dec 18, 2017
Messages
62
Office Version
  1. 365
Platform
  1. Windows
Hi

do you want to keep the file extension (so if filename="c:\temp\test.xlsx", do you need "test" or "test.xlsx")

Thanks
 

edmitchell

Board Regular
Joined
Dec 18, 2017
Messages
62
Office Version
  1. 365
Platform
  1. Windows
Hi

=LEFT(TRIM(RIGHT(SUBSTITUTE(CELL("filename"),"[",REPT(" ",100)),100)),FIND(".",TRIM(RIGHT(SUBSTITUTE(CELL("filename"),"[",REPT(" ",100)),100)))-1)

which will return the filename only. If you could presume that the extension was always 4 characters then it could be a little simpler, but this version looks for the "." between the filename and the extension, and then removes the extension text.
 

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
794

ADVERTISEMENT

Worked Great! Thanks for your help.
 

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
794
Got one more question on this formula. I think what im needing is for the rest of the file name past the first space or before the first bracket . This is what im getting now Example: G4905-910-3 (Bronze Bushings) This is what I would like to see Example: G4905-910-3
 

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
794
Hi

=LEFT(TRIM(RIGHT(SUBSTITUTE(CELL("filename"),"[",REPT(" ",100)),100)),FIND(".",TRIM(RIGHT(SUBSTITUTE(CELL("filename"),"[",REPT(" ",100)),100)))-1)

which will return the filename only. If you could presume that the extension was always 4 characters then it could be a little simpler, but this version looks for the "." between the filename and the extension, and then removes the extension text.

Got one more question on this formula. I think what im needing is for the rest of the file name past the first space or before the first bracket . This is what im getting now Example: G4905-910-3 (Bronze Bushings) This is what I would like to see Example: G4905-910-3
 

edmitchell

Board Regular
Joined
Dec 18, 2017
Messages
62
Office Version
  1. 365
Platform
  1. Windows
Hi

this formula returns the filename up to the first space, is that okay?
=LEFT(TRIM(RIGHT(SUBSTITUTE(CELL("filename"),"[",REPT(" ",100)),100)),FIND(" ",TRIM(RIGHT(SUBSTITUTE(CELL("filename"),"[",REPT(" ",100)),100)))-1)

Regards
 

Watch MrExcel Video

Forum statistics

Threads
1,122,224
Messages
5,594,916
Members
413,952
Latest member
JGer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top