简体   繁体   中英

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

Data: a set of cells B2:B9 with numbers.

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.).

The formula can be, for example:

C2: = B2+1

or

C2: = B2*B2

Normally, I'll define a formula in C2, and copy it to 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. The obvious solution is to define a VBA function. But I don't want to use VBA (if there was a builtin python, then maybe). Instead, I have the simple excel cell formula, and it's convenient.

There's the evaluate function, but I can't supply a parameter, such as the relative cell.

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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