简体   繁体   English

如何通过引用复制单元格公式(或评估单元格公式)?

[英]How do I copy a cell formula by reference (or evaluate a cell formula)?

Data: a set of cells B2:B9 with numbers.数据:一组带有数字的单元格 B2:B9。

Result: kept in C2:C9, where I apply some formula to the relative cell on the left (eg C2 depends on B2, C3 depends on B3, etc.).结果:保存在 C2:C9 中,我将一些公式应用于左侧的相关单元格(例如 C2 取决于 B2,C3 取决于 B3 等)。

The formula can be, for example:例如,公式可以是:

C2: = B2+1 C2: = B2+1

or或者

C2: = B2*B2 C2: = B2*B2

Normally, I'll define a formula in C2, and copy it to C3:C9.通常,我会在 C2 中定义一个公式,并将其复制到 C3:C9。 But any change to the formula would require copying it again.但是对公式的任何更改都需要再次复制。

I'd like to keep the formula in a cell, say C1, and use it in C2:C9.我想将公式保存在一个单元格中,比如 C1,并在 C2:C9 中使用它。 The obvious solution is to define a VBA function.显而易见的解决方案是定义一个 VBA function。 But I don't want to use VBA (if there was a builtin python, then maybe).但我不想使用 VBA(如果有内置的 python,那么也许)。 Instead, I have the simple excel cell formula, and it's convenient.相反,我有简单的 excel 单元格公式,它很方便。

There's the evaluate function, but I can't supply a parameter, such as the relative cell.有评估 function,但我无法提供参数,例如相对单元格。

You can use a table.你可以使用一张桌子。 This will automatically update the column with the formula.这将使用公式自动更新列。

Select your data range, and press CTRL+T (or Insert -> Table). Select 您的数据范围,然后按CTRL+T (或插入 -> 表格)。

Then, enter your formula in the top cell and you'll see the others follow suit.然后,在顶部单元格中输入您的公式,您会看到其他人效仿。

在此处输入图像描述

Edit: Also, note that if you add new rows to the table, they'll automatically get updated with any formulas too.编辑:另外,请注意,如果您向表中添加新行,它们也会自动更新为任何公式。 So there's no need to have "extra" empty rows to keep the formulas there in case new data is added.因此,在添加新数据的情况下,不需要有“额外的”空行来保留公式。 This is automatically done by the Table.这是由表自动完成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM