[英]How do I dynamically change input cell in a formula based on the value in another cell in a spreadsheet?
It is possible to dynamically change the input cell address in a formula based on the content in another cell? 是否可以根据另一个单元格中的内容动态更改公式中的输入单元格地址?
Let's say I have a spreadsheet (excel or libreoffice) with these cell values: 假设我有一个包含以下单元格值的电子表格(excel或libreoffice):
A1: 10
A5: 9
C1: 5
Instead of hardcoding =A1-A5
, I would like to do something like this: =A1-A(C1)
, that would be evaluated at run time to use cell A5
for the second input. 而不是硬编码
=A1-A5
,我想做这样的事情: =A1-A(C1)
,它将在运行时进行评估以将单元格A5
用于第二个输入。
The non-volatile¹ solution would be the INDEX function . 非易失性解决方案将是INDEX函数 。
'for Excel
=A1-INDEX(A:A, C1)
'for OpenOffice
=A1-INDEX(A$1:A$1048576; C1)
¹ Volatile functions recalculate whenever anything in the entire workbook changes, not just when something that affects their outcome changes. ¹ 每当整个工作簿中的任何内容发生更改时,挥发性函数都会重新计算,而不仅仅是影响其结果的某些更改。 Examples of volatile functions are INDIRECT , OFFSET , TODAY , NOW , RAND and RANDBETWEEN .
易失函数的示例包括INDIRECT , OFFSET , TODAY , NOW , RAND和RANDBETWEEN 。 Some sub-functions of the CELL and INFO worksheet functions will make them volatile as well.
CELL和INFO工作表功能的某些子功能也会使它们易失。
Use INDIRECT to take the value in C1 as a pointer to the row that you want in column A:- 使用INDIRECT将C1中的值用作指向您想要在A列中的行的指针:
=A1-INDIRECT("A"&C1)
(tested in Open Office and Excel 2010) (在Open Office和Excel 2010中测试)
For this kind of dynamic reference, you need the INDIRECT
function. 对于这种动态参考,您需要
INDIRECT
函数。 It takes two arguments INDIRECT(reference,style)
它需要两个参数
INDIRECT(reference,style)
reference , a text string containing a cell, a range of cells text or a named range reference ,包含单元格的文本字符串,单元格范围文本或命名范围
and style a boolean that if omitted or TRUE, indicates that reference is A1 style, and when FALSE, the reference is using the R1C1 style. 并为布尔值设置样式 ,如果省略或为TRUE,则表示引用为A1样式,如果为FALSE,则引用使用R1C1样式。
so in your case you can use 因此您可以使用
INDIRECT("A"&C1)
or 要么
INDIRECT("R1C"&C1,FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.