+ Reply to Thread
Results 1 to 7 of 7

inserting variable filename into sumif formula

  1. #1
    Registered User
    Join Date
    01-07-2010
    Location
    seattle, wa
    MS-Off Ver
    Excel 2003
    Posts
    3

    inserting variable filename into sumif formula

    Hello, might be a simple problem, but i don't have the knowledge to figure it out. Basically i have a formula that collects data from an outside worksheet. This formula is repeated several times on the sheet, each calling to a different workbook.

    Problem, it's a pain to have to type in each file name each time, with only two our three characters changing for each one. Is there a simple way to have it automatically fill out the file name based of the cell adjacent? (in this instance its all in reference to dates.

    Here is the function i have:

    Please Login or Register  to view this content.
    The only things that change will be the date on the file name (..."12.18.09, 12.19.09, etc"...) and then some times the month (i do two weeks of information at a time)

    Does that make sense? Thanks - Luke

  2. #2
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: inserting variable filename into sumif formula

    You can put the date into a cell (might have to format the cell as text first) and then use the Indirect function: =SUM(Indirect("'C:\doc...\"&A1&"\["&A2&".xls]... where A1 has the month and A2 has the date.

  3. #3
    Registered User
    Join Date
    01-07-2010
    Location
    seattle, wa
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: inserting variable filename into sumif formula

    Its having a problem with the end of it.

    "sum(indirect('"C:\Doc....\["&D3&".xls]Sheet1'!C5+C6"')"

    That C6"' keeps being highlight and said its wrong. if i take it away it just says #ref!

    so i can't tell if that works or not.

  4. #4
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: inserting variable filename into sumif formula

    I don't think there should be a ' after C6.

  5. #5
    Registered User
    Join Date
    01-07-2010
    Location
    seattle, wa
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: inserting variable filename into sumif formula

    I've tried with every combination with ' or " or nothing. The only thing that doesn't give me an error is with nothing, but it still gives me #ref!

  6. #6
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: inserting variable filename into sumif formula

    Perhaps C5:C6 instead of C5+C6.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: inserting variable filename into sumif formula

    If the target files are not open as and when calculations are performed (implied by link) this approach will I'm afraid to say fail for two reasons

    1 - SUMIF can't be used on closed files

    2 - INDIRECT can't be used on closed files

    Problem 1 can be circumvented using SUMPRODUCT as opposed to SUMIF however Error 2 is fatal.
    If you need to use variable closed files in your formulae you're looking at VBA or 3rd party tools like Laurent Longre's morefunc.xll - specifically the INDIRECT.EXT function contained within.

    If all of the target files are always open as and when these calculations take place then the INDIRECT with SUMIF approach will work (with correct syntax) however being Volatile they will generate (undesired) calculation overheads.

    You might want to have an overall re-think of your approach and rather than using "variable" formulae simply use Static Links and subsequently use Edit -> Replace to update the file references as and when required ?
    Last edited by DonkeyOte; 01-08-2010 at 05:47 AM. Reason: typo

+ 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