Formula-Cell Contain File Extension Without File Path

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
821
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi

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

Thanks
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

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
Back
Top