+ Reply to Thread
Results 1 to 11 of 11

IF argument based on File name?

  1. #1
    Forum Contributor
    Join Date
    09-04-2013
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    117

    IF argument based on File name?

    Morning all.

    Is it possible to create an IF argument based on the filename?

    Example - A2=IF(Filename="template",A1,Filename)

    Reason - A1 is the result of a MAX function on the template WB but once template is saved as a different file name I want A2 to = the new filename?

    Thanks in advance for any advice given.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: IF argument based on File name?

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

    will give you the filename, so:
    =IF(MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)="template.xlsx",A1,MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1))

  3. #3
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: IF argument based on File name?

    To get file name
    =REPLACE(CELL("Filename",$A4),1,FIND("]",CELL("filename",$A4)),"")

    If you create neww workbook you must save it before you can use this kidn of formula.
    If you are http://www.excelforum.com/image.php?type=sigpic&userid=125481&dateline=1392355029happy with the results, please add to the contributor's
    reputation by clicking the reputation icon (star icon).




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.
    To undo, select Thread Tools-> Mark thread as Unsolved.
    http://www.excelaris.co.uk

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: IF argument based on File name?

    @RobertMika - that gives sheet name not file name.

  5. #5
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: IF argument based on File name?

    Quote Originally Posted by yudlugar View Post
    @RobertMika - that gives sheet name not file name.
    Sprry you right youdlugar
    I misread the requirement.

  6. #6
    Forum Contributor
    Join Date
    09-04-2013
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    117

    Re: IF argument based on File name?

    Quote Originally Posted by yudlugar View Post
    =MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

    will give you the filename, so:
    =IF(MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)="template.xlsx",A1,MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1))
    Thank you so much for your help! I shall be testing this out tomorrow and will report back on success.

    Thank again, reputation en route

  7. #7
    Forum Contributor
    Join Date
    09-04-2013
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    117

    Re: IF argument based on File name?

    Quote Originally Posted by yudlugar View Post
    =MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

    will give you the filename, so:
    =IF(MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)="template.xlsx",A1,MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1))
    So i managed to get =MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1) to work in WB-1 Cell A2, the problem ive found is if i have WB-2 open at the same time WB-1 Cell A2 will change to the other WB-2 filename if i enter data into WB-2, when i return to WB-1, Cell A2 has the WB-2s filename until i enter data into WB-1 again & then Cell A2 changes back to WB-1s filenameonce more. This cycle repeats itself again and again to display the WB filename last edited. Is there a way to make this 'lock' to WB-1?

    Any thoughts much appreciated.

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: IF argument based on File name?

    IF you add a reference to the cell function it should solve that I think,

    Replace:
    CELL("filename")
    with
    CELL("filename",A1)

  9. #9
    Forum Contributor
    Join Date
    09-04-2013
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    117

    Re: IF argument based on File name?

    Quote Originally Posted by yudlugar View Post
    IF you add a reference to the cell function it should solve that I think,

    Replace:
    CELL("filename")
    with
    CELL("filename",A1)
    Thanks, tried this but now it just locks the original file name.

    Example - I open Template.xlsm and Cell A1 = Template.Xlsm
    I save Template.xlsm as ABCD.xlsm and cell A1 continues to = Template.xlsm (i.e. it does not update after 'save as')

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: IF argument based on File name?

    I would expect you need to recalculate once you save the file (ctrl+alt+f9).

  11. #11
    Forum Contributor
    Join Date
    09-04-2013
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    117

    Re: IF argument based on File name?

    Quote Originally Posted by yudlugar View Post
    I would expect you need to recalculate once you save the file (ctrl+alt+f9).
    Ah yes! Thank you so much for your help! This has helped me with a workaround from using a macro, i really appreciate your time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using an IF argument & COUNTIF argument in the same cell formula
    By TommyK25 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-14-2013, 08:52 AM
  2. Replies: 2
    Last Post: 02-01-2013, 01:57 PM
  3. [SOLVED] ByRef argument type mismatch / Passing array as a function argument
    By pzling in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2012, 06:23 PM
  4. Replies: 3
    Last Post: 04-28-2010, 05:54 PM
  5. Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 AM

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