Using Indirect() function with a dynamically set named range

%3CLINGO-SUB%20id%3D%22lingo-sub-2295008%22%20slang%3D%22en-US%22%3EUsing%20Indirect()%20function%20with%20a%20dynamically%20set%20named%20range%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2295008%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3ELet's%20say%20that%20in%20%3CSTRONG%3ESheet1%3C%2FSTRONG%3E%20I%20have%20a%20local%20named%20range%20is%20that%20defined%20as%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EName%3A%20Dynamic_Array%3C%2FLI%3E%3CLI%3ERefers%20to%3A%26nbsp%3B%20%3D%24A%241%3AINDEX(%24A%241%3A%24E%241%2C3)%3C%2FLI%3E%3C%2FUL%3E%3CP%3ERange%20A1%3AE1%20has%20number%201%2C2%2C3%2C4%2C5%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20Sheet2%2C%20I%20have%3C%2FP%3E%3CUL%3E%3CLI%3ECell%20A1%20%3D%20Sheet1!%3C%2FLI%3E%3CLI%3ECell%20B1%20%3D%20Dynamic_Arry%3C%2FLI%3E%3CLI%3ECell%20C1%20%3D%20indirect(A1%26amp%3BB1)%3C%2FLI%3E%3C%2FUL%3E%3CP%3Ethe%20Indirect%20formula%20in%20C1%20results%20in%20%23ref%20error.%26nbsp%3B%20I%20understand%20as%20to%20why%20this%20is%20happening%20(Indirect%20formula%20cannot%20work%20with%20a%20named%20range%20that%20is%20defined%20with%20formulas%20because%20it%20requires%20a%20text%20as%20an%20argument)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CU%3EIs%20there%20a%20workaround%20with%20this%3F%26nbsp%3B%3C%2FU%3E%3C%2FP%3E%3CP%3EI%20know%20I%20could%20create%20a%20UDF%20that%20returns%20the%20address%20of%20A1%26amp%3BB1%20and%20do%20something%20like%26nbsp%3B%20%3D%20indirect%20(%20UDF%20(A1%26amp%3BB1))%20and%20make%20it%20work.%20But%20I%20am%20looking%20for%20a%20native%20solution%20to%20what%20UDF%20would%20do.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3EI%20can't%20change%20the%20structure%20of%20the%20workbook%20(I%20cannot%20create%20a%20helper%20look-up%20table%20per%20se.%20I%20have%20thousands%20of%20these%20named%20ranges%20to%20reference)%3C%2FLI%3E%3CLI%3EI%20am%20looking%20for%20a%20native%20Excel%20solution%20to%20this.%26nbsp%3B%3C%2FLI%3E%3CLI%3Exlookup%20or%20vlookup%20does%20not%20work%20with%20the%20structure%20of%20my%20workbook%26nbsp%3B%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2295008%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2295193%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Indirect()%20function%20with%20a%20dynamically%20set%20named%20range%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2295193%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1037339%22%20target%3D%22_blank%22%3E%40PapaAustin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20could%20try%20this%3A%3C%2FP%3E%0A%3CP%3ESelect%20C1%20on%20Sheet2%20(this%20is%20important).%3C%2FP%3E%0A%3CP%3ECreate%20a%20new%20defined%20name%20named%20Eval%20that%20refers%20to%20%3DEvaluate(Sheet2!A1%26amp%3BSheet2!B1)%3C%2FP%3E%0A%3CP%3EEnter%20the%20formula%20%3DEval%20in%20C1%20(or%20in%20C1%3AE1%20as%20in%20the%20screenshot%20below)%3C%2FP%3E%0A%3CP%3EThis%20can%20be%20filled%20down%20if%20you%20have%20other%20sheet%20names%20and%20range%20names.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22S0349.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F275677i31346F0E11F73B78%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22S0349.png%22%20alt%3D%22S0349.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%E2%80%83%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2295317%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Indirect()%20function%20with%20a%20dynamically%20set%20named%20range%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2295317%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1037339%22%20target%3D%22_blank%22%3E%40PapaAustin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20appears%20that%20your%20defined%20name%20'Dynamic_Array'%20returns%20an%20array%20rather%20than%20a%20range%20reference%20so%20is%20ineligible%20as%20an%20argument%20of%20%3CSTRONG%3EINDIRECT%3C%2FSTRONG%3E.%26nbsp%3B%20It%20can%20be%20calculation%20using%20the%20old%20XLM4%20macro%20command%20%3CSTRONG%3EEVALUATE%3C%2FSTRONG%3E.%26nbsp%3B%20This%20only%20works%20using%20Name%20Manager%20rather%20than%20grid%20calculation.%3C%2FP%3E%3CP%3EThat%20is%26nbsp%3B%3C%2FP%3E%3CP%3E%3D%20%3CSTRONG%3EEVAL%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Eworks%2C%20where%20the%20Name%20'EVAL'%20refers%20to%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DEVALUATE(Sheet2!%24A1%26amp%3BSheet2!%24B1)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERather%20better%2C%20if%20you%20can%20switch%20your%20Excel%20365%20to%20the%20Insider's%20Beta%20Channel%2C%20is%20to%20use%20a%20Lambda%20function%20'EVAL%CE%BB'%20which%20refers%20to%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DLAMBDA(n%2CEVALUATE(n))%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EThis%20allows%20you%20to%20use%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3D%20EVAL%CE%BB(A1%26amp%3BB1)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Eon%20the%20worksheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3ENote%3A%20Using%26nbsp%3B%CE%BB%20from%20the%20Greek%20alphabet%2C%20is%20just%20a%20convention%20I%20have%20chosen%20to%20distinguish%20Lambda%20functions%20from%20other%20defined%20names.%26nbsp%3B%20It%20has%20no%20special%20significance%20to%20Excel%20but%20works%20fine.%3C%2FEM%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2295387%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Indirect()%20function%20with%20a%20dynamically%20set%20named%20range%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2295387%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%2C%20Peter.%3CBR%20%2F%3EYes%2C%20I%20understand%20that%20I%20am%20using%20an%20invalid%20argument%20of%20Indirect.%3CBR%20%2F%3EI%20tried%20to%20elaborate%20my%20setup%20in%20the%20response%20below%20(to%20Hans'%20reply)%20and%20why%20it%20would%20be%20impractical%20for%20me%20to%20create%20a%20named%20range%20just%20to%20get%20around%20this%20issue%20(I%20have%20100%2B%20named%20ranges%20to%20reference%20this%20way.%20I%20am%20definitely%20learning%20from%20you%20and%20Hans.%20So%2C%20please%20share%20your%20thoughts.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20to%20Lambda%2C%20I%20do%20have%20Office%20365%20but%20I%20don't%20have%20Lambda!%20(incredibly%20frustrating)%3C%2FP%3E%3CP%3EI'm%20using%20an%20Enterprise%20license%20(version%20information%20below).%20Do%20I%20have%20a%20hope%20of%20getting%20Lambda%20in%20my%20version%20soon-ish%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOffice%20365%3CBR%20%2F%3EVersion%202002%20(Build%2012527.21686%20click-to%20Run)%3CBR%20%2F%3ESemi-annual%20Enterprise%20Channel%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello,

[Edit Apr 27] - Example attached.

 

Let's say that in Sheet1 I have a local named range is that defined as 

  • Name: Dynamic_Array
  • Refers to:  =$A$1:INDEX($A$1:$E$1,3)

Range A1:E1 has number 1,2,3,4,5

 

In Sheet2, I have

  • Cell A1 = Sheet1!
  • Cell B1 = Dynamic_Arry
  • Cell C1 = indirect(A1&B1)

the Indirect formula in C1 results in #ref error.  I understand as to why this is happening (Indirect formula cannot work with a named range that is defined with formulas because it requires a text as an argument)

 

Is there a workaround with this? 

I know I could create a UDF that returns the address of A1&B1 and do something like  = indirect ( UDF (A1&B1)) and make it work. But I am looking for a native solution to what UDF would do. 

 

  1. I can't change the structure of the workbook (I cannot create a helper look-up table per se. I have thousands of these named ranges to reference)
  2. I am looking for a native Excel solution to this. 
  3. xlookup or vlookup does not work with the structure of my workbook 

 

8 Replies

@PapaAustin 

You could try this:

Select C1 on Sheet2 (this is important).

Create a new defined name named Eval that refers to =Evaluate(Sheet2!A1&Sheet2!B1)

Enter the formula =Eval in C1 (or in C1:E1 as in the screenshot below)

This can be filled down if you have other sheet names and range names.

 

S0349.png

@PapaAustin 

It appears that your defined name 'Dynamic_Array' returns an array rather than a range reference so is ineligible as an argument of INDIRECT.  It can be calculation using the old XLM4 macro command EVALUATE.  This only works using Name Manager rather than grid calculation.

That is 

= EVAL

works, where the Name 'EVAL' refers to

=EVALUATE(Sheet2!$A1&Sheet2!$B1)

 

Rather better, if you can switch your Excel 365 to the Insider's Beta Channel, is to use a Lambda function 'EVALλ' which refers to 

=LAMBDA(n,EVALUATE(n))

This allows you to use

= EVALλ(A1&B1)

on the worksheet.

 

Note: Using λ from the Greek alphabet, is just a convention I have chosen to distinguish Lambda functions from other defined names.  It has no special significance to Excel but works fine.

@Hans Vogelaar 

This is really interesting. I haven't come across using =evaluate( ) function in the named range.

However, unfortunately, this can't be a solution for my particular application due to the workbook structure.

 

I could have many [input] sheets with 'dozens' of local range names.

  1. Let's say I have local named ranges called Price1, Price2, ... PriceN
  • This is a time series array. Right now they are statically defined say A(row) : CV(row) - 100 values
  1. I have 10 input sheets called Store1, Store2, Store3, Store4.
    • They all have the same local range names. 
  2. I have a sheet called [Calculations] 
    • in here, I use Sheet names and named ranges using = Indirect ( Sheet!Local_Named_Range)
    • This works flawlessly and does what I need them to do. Very easy to work with

 

But this forces me to work with range names that are defined using the longest possible length all the time. I can reduce my workbook's calculations dramatically if I can make the range named dynamically defined. There is no practical way for me to use your recommendation without fundamentally re-working my workbook (which I am not allowed to do). I was hoping there is a way for me to change the formula to make this work

 

@Peter Bartholomew 

Thank you, Peter.
Yes, I understand that I am using an invalid argument of Indirect.
I tried to elaborate my setup in the response below (to Hans' reply) and why it would be impractical for me to create a named range just to get around this issue (I have 100+ named ranges to reference this way. I am definitely learning from you and Hans. So, please share your thoughts.

 

As to Lambda, I do have Office 365 but I don't have Lambda! (incredibly frustrating)

I'm using an Enterprise license (version information below). Do I have a hope of getting Lambda in my version soon-ish? 

 

Office 365
Version 2002 (Build 12527.21686 click-to Run)
Semi-annual Enterprise Channel

@PapaAustin 

An uninformed guess,  but I would expect it to be a long time (over a year?) before Lambda functions reach a semi-annual license.  The changes made possible by the LET function and LAMBDA can be seismic but it needs to be right.  There is very little that is recognisable from traditional spreadsheet solutions visible in my workbooks.

 

To the best of my knowledge the semi-annual update is a choice made by your IT Admin, not a license restriction.  I believe it is possible for the Admin to select a group of users to have Insider Beta access for purposes such as guiding future policy.

 

As for your present problem, could you mock up a couple of detail sheets and a summary sheet with a few lines of data and sample formula?  For me, this type of development is largely a matter of trial and error rather than firm prior knowledge.  Example questions that might become clear are

1. Are the dynamic changes to the data linked to the time line with every sheet synchronised?

2. Is the content of the detail sheets raw data or dynamic arrays (the use of Tables may aid the first and dynamic range references the second)?

 

Comments: CHOOSE offers an alternative approach to picking up values from a list of sheets (hard-wired as parameters into the function.  Another approach to the dynamic range would be to access the full range, as you do now, but then to apply the OFFSET function to create the reduced size array.

 

For the future, besides allowing the effective use of EVALUATE on the worksheet, LAMBDA functions enable array lookups to be presented in a more developer-friendly manner such as

= ARRAY(sheetIndex, blockIndex, rowIndex, columnIndex)

with all the 'plumbing' discretely hidden.  Recursion can be used to allow arrays of arrays to be aggregated but, as things stand, that is fiercely difficult to implement.  If MAP and REDUCE functions are added to manage the recursion stack, that might become usable without divine inspiration!

 

@PapaAustin 

I think no chances to have LABMDA on this channel soon. Semi-annual is updated by new functionality twice per year, lambda is still only for beta insiders and I don't think it'll go into production in nearest future. I'd expect on semi-annual next (2022) summer or so.

@Peter Bartholomew 

 

Hello Peter,
I uploaded my example in the original post.
It mimics pretty closely what I am trying to do. Except my actual workbook has more data in them.

Please see [Consolidation] sheet where the #ref error is.

 

PapaAustin_0-1619536427306.png

PapaAustin_1-1619536562031.png

 

 

The current version of my workbook works with static named ranges (vs. dynamic named ranges)

i.prod.Gadget1 <- would just have a fixed array of C9 to AZ9 (always 50 months even if I am only modelling the next 20 months)

I have over 2000+ such named ranges. So the static ranges cause a noticeable delay in my calcuations

 

 

@PapaAustin 

Sorry that I was so careless as to overlook the workbook, and then request it!

I cannot find any satisfactory way of returning dynamic arrays using INDIRECT.  I can use CHOOSE to select a specific sheet

= CHOOSE(XMATCH(factory,factory.list),
        Factory1!product.data,
        Factory2!product.data,
        Factory3!product.data)

but its use made little sense where you wanted to sum over each factory.

Maybe, some time in the future, I will be able to demonstrate a Lambda function to return production volumes etc.

= VOLUMEλ(factory, product, month)

and maybe, even to demonstrate new functionality to sum production over a list of factories.