我希望能够根据行/列变量在 Excel 中动态指定范围。
假设我有一个文件,其内容如下所示:
A B C D E 1 10 11 12 13 14 2 51 52 53 54 55
If I wanted to sum the items in row 1, columns 2-4 (i.e. 11 + 12 + 13), how would I specify that?
If I were doing it by hand, I'd type:
=SUM(B1:D1)
...但是我如何以编程方式动态生成该范围定义,只知道所需的行号 (1) 和列号 (2-4)?
=SUM(????)
预先感谢您的帮助!
(我使用的是 Microsoft Excel 2011 for Mac,因此 Excel VBA/基于宏的解决方案不适用于我。)
最佳答案
我有同样的需求 - 看起来 OFFSET
函数可以让你做到这一点。
对于上述内容:
=SUM(OFFSET(A1,0,1,1,3))
分解:
OFFSET(reference cell,
row offset from ref cell to start the range,
col offset to start the range, height of range you want,
width of range you want)
如果需要,您可以将偏移量设置为零,或者+
向下引用,-
向上引用
关于excel - 如何指定 Excel 变量范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6233592/