I primarily use LibreOffice Calc instead of Excel. When creating my spreadsheet, I relied upon the fact that the ADDRESS
function was able to take a cell range and return an array of cell reference strings. But this doesn't work in Excel as the function doesn't work on arrays.
I have a table of values from which I want to sum selected columns in a row. The columns to select is named cell range mycols
and the row is myrow
, giving the following formula:
=SUMPRODUCT(INDIRECT(ADDRESS(myrow, mycols)))
For example:
ADDRESS
returns{$A$2, $D$2, $B$2}
withmyrow=2
andmycols={1,4,2}
(but only$A$2
in Excel).INDIRECT
returns the cell values{1,2,3}
.SUMPRODUCT
returns6
in LibreOffice, but1
in Excel.
I tried using the RC
notation instead and concatenating arrays, but concatenation isn't note element-wise so this doesn't work. I'd like not to use macros.
myCols
=={1,4,2}
and not the string{1,4,2}
: In Excel 2010, try entering this as an array formula by holding downctrl+shift
while hittingenter
. In more recent versions of Excel with dynamic arrays, you can use=ADDRESS(myRow,myCols#)
ADDRESS
has the same result with ctrl+shift+enter. I'd also like to maintain compatibility and LibreOffice doesn't seem to support dynamic arrays.ADDRESS
function. If theADDRESS
formula in Excel 2010 still only returns the single value withctrl+shift+enter
, I cannot help you with an Excel formula solution. I do not have 2010 on my system so cannot test anything. Hopefully another will have a solution that works for you that does not involve upgrading all of your Excel installations.=SUM(A1;D1;B1)
? Tell us in more detail why you chose such a complex and unreliable method, what is the reason for such an approach to extracting values from a table. I wanted to suggest something like=SUMPRODUCT(INDEX($A$1:$D$40;myrow;mycols))
or=SUMPRODUCT(OFFSET($A$1;myrow-1;mycols-1))
, but a quick check showed that Excel does not process such constructions correctly ...INDEX
orOFFSET
work in the way I want, returning an array given an array of columns.