[英]Excel: dynamic array formula
I have an Excel sheet as in the picture. 我有一张Excel表格,如图所示。 I want to make a variable array formula that uses the value in cell E1. 我想制作一个使用单元格E1中的值的变量数组公式。
Cell D4 has the following formula, which works fine: Cell D4具有以下公式,可以正常工作:
{=SUM(A3:A5*B3:B5)}
But, cell D5, where I try to use E5 together with OFFSET does not work: 但是,我尝试将E5与OFFSET一起使用的单元格D5不起作用:
{=SUM(A3:OFFSET(A3,E1,0)*B3:B5)} {= SUM(A3:OFFSET(A3,E1,0)* B3:B5)}
Could anybody explain how to make this "dynamic" array formula work? 任何人都可以解释如何使这个“动态”数组公式工作?
In your example, the portion 在你的例子中,部分
A3:OFFSET(A3,E1,0)
would resolve to the range 会解决范围
A3:A6
ie a range comprising 4 rows. 即包括4行的范围。 Evidently multiplying this range with one comprising just 3 rows ( B3:B5
) will error. 显然将此范围乘以仅包含3行( B3:B5
)的范围将会出错。
In any case, it's preferable to avoid the volatile OFFSET
. 在任何情况下,最好避免挥发性OFFSET
。
Try: 尝试:
=SUM(A3:INDEX(A3:A5,E1)*B3:B5)
with CSE
(although I have to confess that I'm not quite sure why you aren't using SUMPRODUCT
without CSE
). 与CSE
(虽然我不得不承认我不确定为什么你没有使用没有CSE
SUMPRODUCT
)。
I'm also not sure I understand the extent to which this set-up is 'dynamic', since the value in E1
must be consistent with the number of rows hard-coded within the other range in the formula ( B3:B5
here). 我也不确定我理解这个设置是“动态”的程度,因为E1
的值必须与公式中其他范围内硬编码的行数一致( B3:B5
) 。 As such, in reality you only have one choice for the value in E1
; 因此,实际上您只能选择E1
的值; all others will produce an error. 所有其他人都会产生错误。 Unless you intend to incorporate that value within the second range also? 除非您打算将该值纳入第二范围内吗? For example: 例如:
=SUM(A3:INDEX(A3:A5,E1)*B3:INDEX(B3:B5,E1))
Regards 问候
Try to reshape the range with OFFSET rather than changing the starting position. 尝试使用OFFSET重塑范围而不是更改起始位置。
=SUM(OFFSET(A3, 0, 0, E1, 1)*OFFSET(b3, 0, 0, E1, 1))
This is the equivalent of, 这相当于,
=sum(A3:A5*B3:B5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.