I want excel to retrive the name of the worksheet in a cell?

clausboss

Board Regular
Joined
Sep 13, 2005
Messages
71
Hi

I know that I can make =CELL("filename") to get the file name but if I only wante to retrive the sheet name in file is this possible.

:oops:

Claus
 
You were right the first time. I did not want the path. I'm just trying to fill in different information in separate cells. I see that XL doesn't want to give me the folder name using your previous workbook name post. Would you alter Aladin's formula?

Thanks in advance,
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You were right the first time. I did not want the path. I'm just trying to fill in different information in separate cells. I see that XL doesn't want to give me the folder name using your previous workbook name post. Would you alter Aladin's formula?

Thanks in advance,
 
Upvote 0
:oops: :oops: :oops:

It's so hard to concentrate with egg on your face!

=LEFT(CELL("filename",A1),SEARCH("\",CELL("filename",A1)))

I am playing with your formula and changed the ] to \. The return was C:\ When I changed the formula to

=LEFT(CELL("filename",A1),SEARCH("\",CELL("filename",A1))+3 [hoping to to out three \ to pull only the folder name. The formula returns c:\Doc


Is there a way to pull only the folder name?

I'll try to push the button only once this time.......
 
Upvote 0
I'm assuming that when you say "folder name" you mean just the folder at the end of the path. This is tough with just a formula since you don't know how many backslashes will be in the path and you're working right-to-left. But very easy with VBA. Just drop the following UDF into a standard module and then type =udfMyFolder() into a cell.

<font face=Courier New>
<SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Function</SPAN> udfMyFolder() <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> varPath <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Variant</SPAN>
    varPath = Split(ThisWorkbook.Path, Application.PathSeparator)
    udfMyFolder = varPath(UBound(varPath))
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN>
</FONT>
 
Upvote 0
JustMe,

I just happened to be stepping through some code of my own and ran through the following function. It's not a UDF to be used in a cell, but rather to be called from a VBA subroutine. But it just fit so nicely with this theme that I thought I'd post it in case you'd ever need something like it.
Code:
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Private Function HighestPathBranch(ByVal strPath As String) As String
'______________________________________________________________________

' Returns the highest level folder of a path string

    Dim strPS As String, varParts As Variant
    
    strPS = Application.PathSeparator
    If Right(strPath, 1) = strPS Then strPath = Left(strPath, Len(strPath) - 1)
    varParts = Split(strPath, strPS)
    HighestPathBranch = varParts(UBound(varParts))

End Function
 
Upvote 0

Forum statistics

Threads
1,225,191
Messages
6,183,460
Members
453,160
Latest member
DaveM_26

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