Using a cell reference indirectly in a formula

%3CLINGO-SUB%20id%3D%22lingo-sub-2142918%22%20slang%3D%22en-US%22%3EUsing%20a%20cell%20reference%20indirectly%20in%20a%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2142918%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3EI%20have%20a%20spreadsheet%20containing%20multiple%20cases%20arranged%20horizontally%20(each%20case%20muliple%20columns)%20with%20time%20depending%20changes%20vertically.%26nbsp%3B%3C%2FP%3E%3CTABLE%20border%3D%221%22%20width%3D%22100.00000000000001%25%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2257px%22%3E%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2257px%22%3ECase1_Value1%20%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2257px%22%3E%26nbsp%3BCase1_Value2%20%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2257px%22%3E%26nbsp%3BCase1_Value3%20%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2257px%22%3E%26nbsp%3BCase2_Value1%20%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%228.333333333333334%25%22%20height%3D%2257px%22%3E%26nbsp%3BCase2_Value2%20%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%228.333333333333334%25%22%20height%3D%2257px%22%3ECase2_Value3%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E%3CP%3Et1%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E1%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E3%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E2%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E3%3C%2FTD%3E%3CTD%20width%3D%228.333333333333334%25%22%20height%3D%2230px%22%3E2%3C%2FTD%3E%3CTD%20width%3D%228.333333333333334%25%22%20height%3D%2230px%22%3E1%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3Et2%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E4%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E4%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E5%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E3%3C%2FTD%3E%3CTD%20width%3D%228.333333333333334%25%22%20height%3D%2230px%22%3E6%3C%2FTD%3E%3CTD%20width%3D%228.333333333333334%25%22%20height%3D%2230px%22%3E3%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3Et3%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E...%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%2216.666666666666668%25%22%20height%3D%2230px%22%3E%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%228.333333333333334%25%22%20height%3D%2230px%22%3E%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%228.333333333333334%25%22%20height%3D%2230px%22%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20the%20position%20of%20the%20maximum%20for%20each%20case%2C%20like%3C%2FP%3E%3CTABLE%20border%3D%221%22%20width%3D%2256.25%25%22%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%2225%25%22%3E%26nbsp%3B%3C%2FTD%3E%3CTD%20width%3D%2225%25%22%3ECase1%3C%2FTD%3E%3CTD%20width%3D%2225%25%22%3ECase%202%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2225%25%22%20height%3D%2230px%22%3E%3CP%3Et1%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%2225%25%22%3ECase1_Value2%3C%2FTD%3E%3CTD%20width%3D%2225%25%22%3ECase2_Value1%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2225%25%22%20height%3D%2230px%22%3Et2%3C%2FTD%3E%3CTD%20width%3D%2225%25%22%3ECase1_Value3%3C%2FTD%3E%3CTD%20width%3D%2225%25%22%3ECase2_Value2%20%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%2225%25%22%20height%3D%2230px%22%3Et3%3C%2FTD%3E%3CTD%20width%3D%2225%25%22%3E...%3C%2FTD%3E%3CTD%20width%3D%2225%25%22%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20the%20numbers%20of%20columns%20in%20which%20this%20matrix%20is%20safed%20is%20at%20the%20maximum%2C%20I%20need%20to%20extract%20this%20information%20on%20a%20separate%20sheet.%20Since%20I%20know%20how%20many%20columns%20each%20case%20has%20I%20can%20calulate%20the%20number%20of%20the%20columns%20for%20each%20case.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20managed%20to%20extract%20the%20maximum%3A%26nbsp%3B%3DMAX(INDIRECT(ADDRESS(D4%2B1%2CE%242%2C%2C%2C%22Matrix%22))%3AINDIRECT(ADDRESS(D4%2B1%2CF%242%2C%2C%2C%22Matrix%22)))%3C%2FP%3E%3CP%3Efor%20which%20in%20D4%20is%20the%20row%20number%20and%20in%20E2%20and%20F2%20I%20calculated%20the%20column%20number%20(min%20and%20max).%20However%2C%20if%20I%20try%20to%20extract%20the%20position%20of%20the%20maximum%2C%20I%20get%20an%20error.%3C%2FP%3E%3CP%3E%3DINDEX(Matrix!B%241%3AEP%241%2CMATCH(MAX(INDIRECT(ADDRESS(D4%2B1%2CE%242%2C%2C%2C%22Matrix%22))%3AINDIRECT(ADDRESS(D4%2B1%2CF%242%2C%2C%2C%22Matrix%22)))%2CINDIRECT(ADDRESS(D4%2B1%2CE%242%2C%2C%2C%22Matrix%22))%3AINDIRECT(ADDRESS(D4%2B1%2CF%242%2C%2C%2C%22Matrix%22))%3AINDIRECT(ADDRESS(D4%2B1%2CE%242%2C%2C%2C%22Matrix%22))%3AINDIRECT(ADDRESS(D4%2B1%2CF%242%2C%2C%2C%22Matrix%22)))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20help%20is%20much%20appreciated!%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2142918%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2144544%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20a%20cell%20reference%20indirectly%20in%20a%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2144544%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F969514%22%20target%3D%22_blank%22%3E%40doehring%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMay%20I%20make%20a%20suggestion%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYour%20request%20for%20help%20has%20been%20up%20for%209%20hours%20with%20no%20response.%20My%20guess%20is%20that%20people%20don't%20really%20know%20where%20to%20begin.%20You%20show%20an%20elaborate%20formula%20that%20doesn't%20work%2C%20and%20a%20mock-up%20of%20the%20actual%20spreadsheet%20where%20that%20formula%20doesn't%20work.%20You%20would%20help%20us%20help%20you%20if%20you%20posted%20the%20actual%20spreadsheet%2C%20so%20we%20wouldn't%20have%20to%20create%20a%20small%20and%20possibly%20off%3Dbase%20copy%20based%20on%20that%20little%20glimpse%20you%20give.%20Just%20make%20sure%20it%20contains%20no%20confidential%20information.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20if%20you%20could%20describe%20just%20a%20bit%20more%20of%20the%20context%20here.%20What%20is%20the%20task%2C%20the%20bigger%20task%2C%20of%20which%20this%20spreadsheet%20is%20just%20a%20part%3F%20Why%20is%20it%20laid%20out%20as%20it%20is%3F%20How%20long%20has%20it%20been%20going%20on%2C%20to%20now%20have%20reached%20the%20limits%20of%20Excel%3F%20That%20kind%20of%20stuff.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2144625%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20a%20cell%20reference%20indirectly%20in%20a%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2144625%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F969514%22%20target%3D%22_blank%22%3E%40doehring%3C%2FA%3E%26nbsp%3BAlthough%20i%20agree%20with%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F425987%22%20target%3D%22_blank%22%3E%40mathetes%3C%2FA%3E%26nbsp%3BI%20think%20I%20see%20your%20problem.%26nbsp%3B%20I%20must%20also%20would%20try%20to%20avoid%20using%20indirect.%26nbsp%3B%20You%20could%20use%20INDEX()%20or%20better%20yet%20just%20NAME%20the%20ranges%20or%20at%20least%20use%20the%20LET()%20function%20if%20you%20have%20that%20available%20so%20excel%20doesn't%20have%20to%20recalculate%20those%20references%20each%20time.%26nbsp%3B%20%26nbsp%3BThat%20said%20I%20believe%20your%20problem%20is%20that%20your%20MATCH%20doesn't%20declare%20it%20to%20be%20an%20exact%20match%20and%20I%20think%20you%20were%20missing%20a%20%22)%22.%26nbsp%3B%20I%20also%20don't%20understand%20why%20you%20have%20the%20range%202x.%26nbsp%3B%20Try%20this%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DINDEX(Matrix!B%241%3AEP%241%2CMATCH(MAX(INDIRECT(ADDRESS(D4%2B1%2CE%242%2C%2C%2C%22Matrix%22))%3AINDIRECT(ADDRESS(D4%2B1%2CF%242%2C%2C%2C%22Matrix%22)))%2CINDIRECT(ADDRESS(D4%2B1%2CE%242%2C%2C%2C%22Matrix%22))%3AINDIRECT(ADDRESS(D4%2B1%2CF%242%2C%2C%2C%22Matrix%22))%2C0))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2146062%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20a%20cell%20reference%20indirectly%20in%20a%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2146062%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F969514%22%20target%3D%22_blank%22%3E%40doeh%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMockup%20for%20dynamic%20array%20variant%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20752px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F255768i2BA860B263FDFFC2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3Ecould%20be%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DLET(%0A%20%20%20h%2C%20%24C%242%3A%24H%242%2C%20t%2C%20%24B%243%3A%24B%244%2C%20r%2C%20%24C%243%3A%24H%244%2C%0A%20%20%20hr%2C%20K%242%2C%20tr%2C%20%24J3%2C%0A%20%20%20a%2C%20%20--(hr%3DLEFT(TRIM(h)%2C5))%2C%0A%20%20%20b%2C%20%20a*SEQUENCE(1%2CCOUNTA(h))%2C%0A%20%20%20c%2C%20%20FILTER(b%2Cb)%2C%0A%20%20%20d%2C%20%20INDEX(r%2C%20XMATCH(tr%2Ct)%2Cc)%2C%0A%20%20%20e%2C%20%20XMATCH(MAX(d)%2C%0A%20%20%20d)%2C%20INDEX(h%2CINDEX(c%2Ce))%0A)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello,

I have a spreadsheet containing multiple cases arranged horizontally (each case muliple columns) with time depending changes vertically. 

 Case1_Value1   Case1_Value2   Case1_Value3   Case2_Value1   Case2_Value2  Case2_Value3

t1

132321
t2445363
t3...     

 

I need the position of the maximum for each case, like

 Case1Case 2

t1

Case1_Value2Case2_Value1
t2Case1_Value3Case2_Value2  
t3... 

 

Since the numbers of columns in which this matrix is safed is at the maximum, I need to extract this information on a separate sheet. Since I know how many columns each case has I can calulate the number of the columns for each case.

 

I have managed to extract the maximum: =MAX(INDIRECT(ADDRESS(D4+1,E$2,,,"Matrix")):INDIRECT(ADDRESS(D4+1,F$2,,,"Matrix")))

for which in D4 is the row number and in E2 and F2 I calculated the column number (min and max). However, if I try to extract the position of the maximum, I get an error.

=INDEX(Matrix!B$1:EP$1,MATCH(MAX(INDIRECT(ADDRESS(D4+1,E$2,,,"Matrix")):INDIRECT(ADDRESS(D4+1,F$2,,,"Matrix"))),INDIRECT(ADDRESS(D4+1,E$2,,,"Matrix")):INDIRECT(ADDRESS(D4+1,F$2,,,"Matrix")):INDIRECT(ADDRESS(D4+1,E$2,,,"Matrix")):INDIRECT(ADDRESS(D4+1,F$2,,,"Matrix")))

 

Any help is much appreciated!

Thanks

6 Replies

@doeh 

 

May I make a suggestion?

 

Your request for help has been up for 9 hours with no response. My guess is that people don't really know where to begin. You show an elaborate formula that doesn't work, and a mock-up of the actual spreadsheet where that formula doesn't work. You would help us help you if you posted the actual spreadsheet, so we wouldn't have to create a small and possibly off=base copy based on that little glimpse you give. Just make sure it contains no confidential information.

 

And if you could describe just a bit more of the context here. What is the task, the bigger task, of which this spreadsheet is just a part? Why is it laid out as it is? How long has it been going on, to now have reached the limits of Excel? That kind of stuff.

@doeh Although i agree with @mathetes I think I see your problem.  I must also would try to avoid using indirect.  You could use INDEX() or better yet just NAME the ranges or at least use the LET() function if you have that available so excel doesn't have to recalculate those references each time.   That said I believe your problem is that your MATCH doesn't declare it to be an exact match and I think you were missing a ")".  I also don't understand why you have the range 2x.  Try this:

=INDEX(Matrix!B$1:EP$1,MATCH(MAX(INDIRECT(ADDRESS(D4+1,E$2,,,"Matrix")):INDIRECT(ADDRESS(D4+1,F$2,,,"Matrix"))),INDIRECT(ADDRESS(D4+1,E$2,,,"Matrix")):INDIRECT(ADDRESS(D4+1,F$2,,,"Matrix")),0))

 

@doeh 

Mockup for dynamic array variant

image.png

could be

 

=LET(
   h, $C$2:$H$2, t, $B$3:$B$4, r, $C$3:$H$4,
   hr, K$2, tr, $J3,
   a,  --(hr=LEFT(TRIM(h),5)),
   b,  a*SEQUENCE(1,COUNTA(h)),
   c,  FILTER(b,b),
   d,  INDEX(r, XMATCH(tr,t),c),
   e,  XMATCH(MAX(d),
   d), INDEX(h,INDEX(c,e))
)

 

 

@mathetes 

Thank you for your reply and you are absolutely right! Sorry, for not replying earlier I had to work in between. I will add more details and a sample spreadsheet the next time I ask a question. Thank you for your response and help!

@mtarler
Thank you I have just tried it and it works and it is much quicker, then most of my other formulas. Thank you!
@Sergei Baklan
Thank you for your response and the file. I have never used a dynamic array before in Excel. This looks very interesting to use.
Thank you again!