ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Insert file name in cell without .xls extension (https://www.excelbanter.com/excel-discussion-misc-queries/126604-insert-file-name-cell-without-xls-extension.html)

Steve

Insert file name in cell without .xls extension
 
I know that I can enter a cell file name with the following typed into the
cell:
=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

But, can I do this without showing the file extension (.xls)?

ExcelBanter AI

Answer: Insert file name in cell without .xls extension
 
Code:

  1. Type the following formula into the cell where you want to display the file name without the extension:
    =LEFT(MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1),FIND(".",MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1))-1)
  2. Press Enter to see the file name displayed in the cell without the extension.

This formula uses the LEFT function to extract the characters from the left of the file name until the first period (.) is encountered, which is where the file extension starts. By doing this, the file extension is excluded from the displayed file name.

Ron Coderre

Insert file name in cell without .xls extension
 
Maybe something like this?:

=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH(".xl?]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

Does that help?
***********
Regards,
Ron

XL2002, WinXP


"Steve" wrote:

I know that I can enter a cell file name with the following typed into the
cell:
=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

But, can I do this without showing the file extension (.xls)?


JE McGimpsey

Insert file name in cell without .xls extension
 
One way:

=MID(LEFT(CELL("filename",A1), FIND("]", CELL("filename", A1)) - 5),
FIND("[", CELL("filename", A1)) + 1, 255)

In article

,
Steve wrote:

I know that I can enter a cell file name with the following typed into the
cell:
=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

But, can I do this without showing the file extension (.xls)?


Steve

Insert file name in cell without .xls extension
 
Thanks, Ron, it worked! I also found that this works as well (removes last 4
digits by changing -1 to -5, but I like your solution better:
=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-5)

"Ron Coderre" wrote:

Maybe something like this?:

=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH(".xl?]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

Does that help?
***********
Regards,
Ron

XL2002, WinXP


"Steve" wrote:

I know that I can enter a cell file name with the following typed into the
cell:
=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

But, can I do this without showing the file extension (.xls)?


Benjamin Newton

Hello,
I realise that this is by no means a current thread but having just tried it out I thought I should feed back my findings:
If you have two worksheets open that both use any of these formulas the first one opened will display correctly until the second one is opened, whereupon it will display the filename of the second file. Pressing F9 to recalculate will result in both worksheets displaying the filename of the currently active sheet.
The formula is great, but is there anyway around the above little problem?

Kind regards
Benjamin
Quote:

Originally Posted by Steve (Post 435343)
Thanks, Ron, it worked! I also found that this works as well (removes last 4
digits by changing -1 to -5, but I like your solution better:
=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-5)

"Ron Coderre" wrote:

Maybe something like this?:

=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH(".xl?]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

Does that help?
***********
Regards,
Ron

XL2002, WinXP


"Steve" wrote:

I know that I can enter a cell file name with the following typed into the
cell:
=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

But, can I do this without showing the file extension (.xls)?


Benjamin Newton

OK I'm now replying to my own posts...

Actually one of the formulas was different. The ones that use FIND work ok, the ones that use SEARCH are problematic with two or more sheets. This is due to the ones that use FIND referring to a cell in that worksheet. For an explanation of this see here;

http://www.xldynamic.com/source/xld.xlFAQ0002.html

So I now have two formulas:

=MID(LEFT(CELL("filename",A1), FIND("]", CELL("filename", A1)) - 5),
FIND("[", CELL("filename", A1)) + 1, 255)

or one from here
http://www.excelbanter.com/showthread.php?t=153010
=MID(CELL("FILENAME",A1),FIND("[",CELL("FILENAME",A1))+1,FIND("]",CELL("FILENAME",A1))-FIND("[",CELL("FILENAME",A1))-5)

For me they both work, but which one is more elegant?

Many thanks

Benjamin

Quote:

Originally Posted by Benjamin Newton (Post 1600823)
Hello,
I realise that this is by no means a current thread but having just tried it out I thought I should feed back my findings:
If you have two worksheets open that both use any of these formulas the first one opened will display correctly until the second one is opened, whereupon it will display the filename of the second file. Pressing F9 to recalculate will result in both worksheets displaying the filename of the currently active sheet.
The formula is great, but is there anyway around the above little problem?

Kind regards
Benjamin


sk.shafiqul

Quote:

Originally Posted by Benjamin Newton (Post 1600824)
OK I'm now replying to my own posts...

Actually one of the formulas was different. The ones that use FIND work ok, the ones that use SEARCH are problematic with two or more sheets. This is due to the ones that use FIND referring to a cell in that worksheet. For an explanation of this see here;

http://www.xldynamic.com/source/xld.xlFAQ0002.html

So I now have two formulas:

=MID(LEFT(CELL("filename",A1), FIND("]", CELL("filename", A1)) - 5),
FIND("[", CELL("filename", A1)) + 1, 255)

or one from here
http://www.excelbanter.com/showthread.php?t=153010
=MID(CELL("FILENAME",A1),FIND("[",CELL("FILENAME",A1))+1,FIND("]",CELL("FILENAME",A1))-FIND("[",CELL("FILENAME",A1))-5)

For me they both work, but which one is more elegant?

Many thanks

Benjamin


HI SIR,

# CAN POSSIBLE IT IN VB?
# CAN I SOWN ONLY FIRST 6 DIGIT OF FILE NAME?

sk.shafiqul

[quote=sk.shafiqul;1606034]HI SIR,

# CAN POSSIBLE IT IN VB?

again

can possible to show only last 9 digit of file name?

Shafiq
BD


All times are GMT +1. The time now is 05:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com