简体   繁体   English

如何基于电子表格中另一个单元格中的值动态更改公式中的输入单元格?

[英]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)

nonvolatile_index
nonvolatile_index_oo


¹ 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 . 易失函数的示例包括INDIRECTOFFSETTODAYNOWRANDRANDBETWEEN Some sub-functions of the CELL and INFO worksheet functions will make them volatile as well. CELLINFO工作表功能的某些子功能也会使它们易失。

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.

相关问题 如何根据另一个单元格的值更改单元格的公式 - How can I change the formula of the cell according to the value of another cell 公式中的行根据另一个单元格中的值更改 - Row in formula change based on value in another cell 如何根据另一个单元格更改单元格中的文本? - How do I change text in a cell based on another cell? 如何基于Excel电子表格中的指向值在公式中创建动态单元格 - How to make dynamic cell in formula based on pointed value in excel spreadsheet 如何根据另一个单元格将单元格值限制为最大值? - How do I restrict a cell value to a maximum based on another cell? 如何动态更改单元格的公式 - How dynamically to change the formula of a cell 从单元格获取值并使用其引用另一个电子表格中单元格的公式? - Formula to grab value from a cell and use that to refer to a cell in another spreadsheet? 如何根据另一个电子表格中单元格中手动选择的颜色(而不是基于单元格值)设置单元格颜色 - How to set cell color based on a manually selected color (not based on cell value) in a cell in another spreadsheet 如何读取电子表格单元格而不是公式的显示值? - How to read the displayed value of a spreadsheet cell, not the formula? 如何为单元格添加公式值? - How do I append a cell with a formula value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM