+ Reply to Thread
Results 1 to 6 of 6

how to specify variable range in link?

  1. #1
    Registered User
    Join Date
    06-08-2010
    Location
    london, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    how to specify variable range in link?

    i'd like a way to compute based on a variable range to data in a linked file. for example, it's easy to do something static:

    =sum([data.xls]data!a1:a15)

    however, i need the range portion to be variable, so i could so something like this pseudocode:

    =sum([data.xls]data!INDIRECT(c3))

    where c3 is computed string like "a1:a15"

    the attached sheet has an example.

    can this be done just using functions; i.e. no VB code/macros?

    thanks.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: how to specify variable range in link?

    C3: ="[data.xls]data!A1:A" & A1
    Ben Van Johnson

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

    Re: how to specify variable range in link?

    Note that native INDIRECT will only work if the target file is open.

    If you're working with closed files then the native INDIRECT function is not a viable approach I'm afraid and you will be looking at VBA in some guise.
    (else modify the links via Edit/Replace as and when required)

  4. #4
    Registered User
    Join Date
    06-08-2010
    Location
    london, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: how to specify variable range in link?

    first, *thanks* for the responses.

    following protonLeah's lead, i made c3 = "data!A1:A" & C3. where c5 = sum(indirect(c3)), it returned 120, the correct answer. so this works for the references within the workbook.

    as a test, i then changed c3 = 'C:\Documents and Settings\user\Desktop\[data.xls]data'!$A$1:$A$20

    this returns a #REF! error. i then tried opening data.xls, but that didn't make a difference. (not surprising since INDIRECT is getting its value locally, not from the linked file.)

    i'm guessing then that either INDIRECT can't/won't properly return a path, or the recipient function (SUM, in this case) doesn't like what INDIRECT is returning, or maybe there's some combination of quoting of the path that i'm not doing correctly. or what am i missing? am i forced to use VB to do what i need? suggestions/clarifications appreciated.

  5. #5
    Registered User
    Join Date
    06-08-2010
    Location
    london, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: how to specify variable range in link?

    okay, the third option was the problem: the quoting i used.

    when if had c3 = 'C:\Documents and Settings\rchong\Desktop\[data.xls]data'!$A$1:$A$20

    it didn't work. on a whim, i added another single quote (as in two single quotes, not a single double quote) to the front:

    c3 = ''C:\Documents and Settings\rchong\Desktop\[data.xls]data'!$A$1:$A$20

    this worked! sadly though, but only when data.xls is open. crazy.

    so...i guess the problem was with my understanding. it seems INDIRECT returns a reference rather than the contents. (??) i want the contents so that SUM can go open the file and do its thing. hmm...

  6. #6
    Registered User
    Join Date
    06-08-2010
    Location
    london, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: how to specify variable range in link?

    i tried named ranges and OFFSET, but they don't work with unopened files either. time to look at VB. any tips of where/how to start? most of my uses would be with array formulas. thanks.

+ 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