Using Name Variable within External Workbook Lookup Path

%3CLINGO-SUB%20id%3D%22lingo-sub-2208425%22%20slang%3D%22en-US%22%3EUsing%20Name%20Variable%20within%20External%20Workbook%20Lookup%20Path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2208425%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20lookup%20to%20an%20eternal%20workbook%20currently%20taking%20place%20using%20the%20following%20formula%3A%3C%2FP%3E%3CP%3E%3DSUM('C%3A%5CUsers%5Cjames%5COneDrive%5CDocuments%5CWork%5CFinancial%5CSales%20Figures%5C2019%5C%5BJames.xls%5DSummary'!%24F%247%3A%24F%2418)%3CBR%20%2F%3E%3CBR%20%2F%3EOn%20a%20second%20worksheet%20called%20Settings%2C%20I%20have%20defined%20a%20cell%20named%20%22CurrentYear%22%20with%20the%20value%20%222020%22%2C%20which%20I%20want%20to%20replace%20the%20%222019%22%20with%20in%20the%20current%20formula%20to%20save%20me%20from%20updating%20all%20of%20the%20years%20in%20the%20formulas%20manually%2C%20ie.%26nbsp%3B%3DSUM('C%3A%5CUsers%5Cjames%5COneDrive%5CDocuments%5CWork%5CFinancial%5CSales%20Figures%5C%3CSTRONG%3ECurrentYear%3C%2FSTRONG%3E%5C%5BJames.xls%5DSummary'!%24F%247%3A%24F%2418)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20anyone%20clarify%20the%20syntax%20to%20get%20this%20to%20work%3F%20I%20have%20tried%20inserting%20speechmarks%20and%20ampersands%20around%20the%20file%20path%20and%20name%20but%20then%20the%20external%20workbook%20lookup%20does%20not%20seem%20to%20work.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2208425%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2208528%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Name%20Variable%20within%20External%20Workbook%20Lookup%20Path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2208528%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F996734%22%20target%3D%22_blank%22%3E%40jamesbeale%3C%2FA%3E%20You%20can%20use%20the%20INDIRECT%20function%2C%20but%20(and%20this%20is%20a%20big%20BUT!)%2C%20this%20function%20only%20works%20with%20references%20to%20another%20workbook%20if%20that%20workbook%20is%20open%20in%20Excel.%20Otherwise%2C%20INDIRECT%20will%20return%20%23REF!%3C%2FP%3E%0A%3CP%3EThe%20formula%20would%20be%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DSUM(%22'C%3A%5CUsers%5Cjames%5COneDrive%5CDocuments%5CWork%5CFinancial%5CSales%20Figures%5C%22%20%26amp%3B%20CurrentYear%20%26amp%3B%20%22%5C%5BJames.xls%5DSummary'!%24F%247%3A%24F%2418%22)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2208579%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Name%20Variable%20within%20External%20Workbook%20Lookup%20Path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2208579%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%2C%26nbsp%3Bthanks%20for%20your%20reply.%20I%20need%20it%20to%20work%20with%20the%20other%20workbook%20closed%20ideally.%20But%20where%20did%20you%20use%20the%20INDIRECT%20function%3F%20It%20was%20not%20there%20in%20the%20formula%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2208606%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Name%20Variable%20within%20External%20Workbook%20Lookup%20Path%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2208606%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F996734%22%20target%3D%22_blank%22%3E%40jamesbeale%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMy%20apologies%2C%20I%20was%20too%20hasty.%20I%20have%20edited%20the%20formula%20in%20my%20previous%20reply.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi all,

 

I have a lookup to an eternal workbook currently taking place using the following formula:

=SUM('C:\Users\james\OneDrive\Documents\Work\Financial\Sales Figures\2019\[James.xls]Summary'!$F$7:$F$18)

On a second worksheet called Settings, I have defined a cell named "CurrentYear" with the value "2020", which I want to replace the "2019" with in the current formula to save me from updating all of the years in the formulas manually, ie. =SUM('C:\Users\james\OneDrive\Documents\Work\Financial\Sales Figures\CurrentYear\[James.xls]Summary'!$F$7:$F$18)

 

Can anyone clarify the syntax to get this to work? I have tried inserting speechmarks and ampersands around the file path and name but then the external workbook lookup does not seem to work.

 

Thanks.

15 Replies

@jamesbeale You can use the INDIRECT function, but (and this is a big BUT!), this function only works with references to another workbook if that workbook is open in Excel. Otherwise, INDIRECT will return #REF!

The formula would be

 

=SUM(INDIRECT("'C:\Users\james\OneDrive\Documents\Work\Financial\Sales Figures\" & CurrentYear & "\[James.xls]Summary'!$F$7:$F$18"))

Hi @Hans Vogelaar, thanks for your reply. I need it to work with the other workbook closed ideally. But where did you use the INDIRECT function? It was not there in the formula? 

@jamesbeale 

My apologies, I was too hasty. I have edited the formula in my previous reply.

@Hans Vogelaar Thanks. I think the INDIRECT function needs a second parameter also though?

@jamesbeale 

The second argument to INDIRECT is optional. If you omit it, the first argument is treated as a reference in A1 style.

If you specify FALSE as second argument, the first argument is treated as a reference in R1C1 style.

Since your cell reference $F$7:$F$18 is in A1 style, there is no need to use the second argument.

@Hans Vogelaar thanks. I have entered the formula as you said above and with the second workbook open, but still get a #REF! error. Any ideas why?
Below is my formula:
=SUM(INDIRECT("'C:\Users\james\OneDrive\Documents\Work\Financial\Sales Figures\" & Year1 & "\[James.xls]Summary'!$D$7:$D$18"))

where the value of the cell referenced by Year1 is 2021.

@jamesbeale 

It should work:

 

S0206.png

 

S0207.png

 

@Hans Vogelaar I seem to have exactly the same as you but am getting a #REF! error, any ideas why?

 

jamesbeale_1-1615789763916.png

 

 

@jamesbeale 

If you opened Any Shearer.xls after creating the formula (or opening the workbook with the formula), you may have to recalculate the formulas (F9).

If not: are you absolutely sure that the path and filename are correct?

@Hans Vogelaar recalculate doesn't do anything and file path is correct - see below if I evaluate the formula - file path is definitely correct and it seems to insert the year correctly into the path. Is there any formatting error in the file path I am missing?

 

jamesbeale_0-1615797599834.png

jamesbeale_1-1615797667884.png

 

@Hans Vogelaar also I know the file path is 100% correct as if I remove the Year1 name and just put it in as a full file path, it works without an any error. So the error is only coming when inserting the Year1 variable.
only way is to use indirect as sum will not understand address c:\etc

@chahine still gives the same error even with INDIRECT used - see below

jamesbeale_1-1615800411916.png

 

@jamesbeale 

It looks OK to me. I'm afraid I'm out of ideas...

ok , see =SUM("'"&"C:\Users\james\OneDrive\Documents\Work\Financial\Sales Figures\"&indirect(CurrentYear)&"\[James.xls]Summary'!"$F$7:$F$18)

i think now it should work