+ Reply to Thread
Results 1 to 11 of 11

what's wrong w/ this formula?

  1. #1
    Forum Contributor
    Join Date
    06-21-2009
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    200

    what's wrong w/ this formula?

    i want to import the name of my file into my cell. by looking at help i've been able to do that but dont really undestand the formula properly, which will make it hard to modify.

    here's me reverse engineering it. can you please explain why this isn't working, i've getting a #value error.

    =MID( CELL("[hello]"), 2, 5)


    in the original formula (which works) i used cell("filename") which worked fine. but when im evaluating that formula, rather than it showing up as "Hello.xls" it shows up as "c\doc and set \ excel \ journal \ blah blah blah blah \ ... \. ..... \ etc etc \ Hello.xls" which makes it REALLY hard to decode (esp b/c this path is referred to 3 times in the same code). is there a way to go straight for the name w/o the path?
    Last edited by NBVC; 08-19-2011 at 10:15 AM. Reason: moved [Solved] from title to Prefix

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: what's wrong w/ this formula?

    Try this

    =MID(CELL("filename",A1),FIND("[",CELL("filename",A1)),255)

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: what's wrong w/ this formula?

    According to Excel help on CELL() function, using "filename" gets you the whole path... that is why the MID(CELL(.....)) formula exists... to reduce it down to only the file name or sheet name.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: what's wrong w/ this formula?

    One way
    Please Login or Register  to view this content.
    Remember that the workbook has to be a saved workbook for this to work.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  5. #5
    Forum Contributor
    Join Date
    06-21-2009
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    200

    Re: what's wrong w/ this formula?

    thanks a lot for the help fellows. unfortunately you haven't actually answered my question

    i already have the formula i need. that was given in the help files. im just trying to understand it now, and in order to do that i must play w/ it. so i need to understand what's wrong w/ my modified formula:

    =MID( CELL("[hello]"), 2, 5)



    i also want to know if there's any way to reference the file name, so that when im editing the formula i only see the file name, not the path.

    According to Excel help on CELL() function, using "filename" gets you the whole path... that is why the MID(CELL(.....)) formula exists... to reduce it down to only the file name or sheet name.
    if im reading this right there's no way to only see the file name without the path in the formula bar. is this correct? i really hope not.

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: what's wrong w/ this formula?

    You can't use CELL("[hello]") if you read the help files, you must use one of the descriptions shown in the Info_type column.

    http://office.microsoft.com/en-us/ex...010062392.aspx

    if you want to pull Hello from that, it is simply:

    =MID("[hello]", 2, 5)

  7. #7
    Forum Contributor
    Join Date
    06-21-2009
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    200

    Re: what's wrong w/ this formula?

    Quote Originally Posted by NBVC View Post
    You can't use CELL("[hello]") if you read the help files, you must use one of the descriptions shown in the Info_type column.

    http://office.microsoft.com/en-us/ex...010062392.aspx

    if you want to pull Hello from that, it is simply:

    =MID("[hello]", 2, 5)
    ahh OK that makes sense.

    can you advise on the second part of the question?

    >i also want to know if there's any way to reference the file name, so that when im editing
    >the formula i only see the file name, not the path.

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: what's wrong w/ this formula?

    There isn't... the CELL("format",....) function will display the whole path and there is no alternative.... again, that is why the big formula to extract the filename exists.

  9. #9
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: what's wrong w/ this formula?

    Here's an elegant little user defined function that is much clearer and easy to use:
    Please Login or Register  to view this content.
    To use it, paste the code into a code module, then enter a formula like this anywhere in your book:
    Please Login or Register  to view this content.
    To get the sheet name:
    Please Login or Register  to view this content.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  10. #10
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: what's wrong w/ this formula?

    Quote Originally Posted by tlafferty View Post
    Here's an elegant little user defined function that is much clearer and easy to use:
    Except that for the sheet option it doesn't update if the sheet name changes, and if you are on another sheet and do a full recalc, it will then change to that active sheet name.

  11. #11
    Forum Contributor
    Join Date
    06-21-2009
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    200

    Re: what's wrong w/ this formula?

    thanks guys for all the help here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1