简体   繁体   English

防止单元格公式改变

[英]Prevent Cell formula from changing

I've got an Excel sheet where values can be entered.我有一个 Excel 表,可以在其中输入值。

For example:例如:

A2 = product name

B2 = product number

C2 = company number

D2 = "#" (allway's the # sign

E2 = "A1"&"D1"&"B1"&"D1"&"C1"

After a button is pressed a macro wil run.按下按钮后,将运行宏。 The values will automaticly be cut-paste to a history sheet.这些值将自动剪切粘贴到历史记录表中。

The formula of Cell E2 changes into the location where the values are pasted(in this case th hisory sheet).单元格 E2 的公式更改为粘贴值的位置(在本例中为历史记录表)。

I'd like to prevent the formula in Cell E2 to change, so I entered $ signs before the numbers and letters.我想防止单元格 E2 中的公式更改,所以我在数字和字母前输入了 $ 符号。 and entered sheets names before it.并在其之前输入工作表名称。 This did'nt make a differnce at all.这根本没有区别。

Does anyone knows a sollution for this?有谁知道这个解决方案? (or do i juist have to write a vba code that modifys cell E2 back to the formula I need every time the values are cut and paste into the history sheet?) (或者我是否必须编写一个 vba 代码,每次将值剪切并粘贴到历史记录表时,将单元格 E2 修改回我需要的公式?)

Anwser thanks to Jeeped感谢 Jeeped

Use the Indirect function to keep your references static!使用间接函数来保持您的引用静态!

Works perfect for me!非常适合我!

=INDIRECT("'Sheet1'!A2")&INDIRECT("'Sheet1'!D2")& ect. =INDIRECT("'Sheet1'!A2")&INDIRECT("'Sheet1'!D2")& 等。

If you want to keep the formula static no matter wherever you move, copy, displace or other, then the references have to be static text and the INDIRECT is used to return them to valid cell references.如果您想在移动、复制、置换或其他任何地方都保持公式静态,则引用必须是静态文本,并且使用INDIRECT将它们返回到有效的单元格引用。

In E2 as,在 E2 中,

 =INDIRECT("'Sheet1'!A2")&INDIRECT("'Sheet1'!D2")&INDIRECT("'Sheet1'!B2")&INDIRECT("'Sheet1'!D2")&INDIRECT("'Sheet1'!C2")

Adjust the worksheet name if necessary.如有必要,调整工作表名称。 Those cell addresses will not change no matter what you do with them (beyond a text edit).无论您对它们做什么(除了文本编辑),这些单元格地址都不会改变。

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

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