简体   繁体   English

Excel查询 - 在设置公式时需要帮助

[英]Excel query - need help in setting up formula

I have cell A and cell B. Both the cells contain some numeric value, say 2. 我有单元格A和单元格B.两个单元格都包含一些数值,比如2。

Now if i put 3 in cell A, cell B value should automatically update to 5 and so on. 现在,如果我在单元格A中放置3,则单元格B值应自动更新为5,依此类推。

Again, if i put 5 in cell A, cell B value should be 10. 同样,如果我在单元格A中放置5,则单元格B值应为10。

Hope i have made myself clear... 希望我已经明确了......

Any help would be really appreciated. 任何帮助将非常感激。

Thanks Rakesh 谢谢Rakesh

This will work for cells A1 and B1. 这适用于单元格A1和B1。 Put the following event macro in the worksheet code area: 将以下事件宏放在工作表代码区域中:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Range("A1"), Target) Is Nothing Then Exit Sub
    Application.EnableEvents = False
        [B1] = [B1] + [A1]
    Application.EnableEvents = True
End Sub

Because it is worksheet code, it is very easy to install and automatic to use: 因为它是工作表代码,所以很容易安装和自动使用:

  1. right-click the tab name near the bottom of the Excel window 右键单击Excel窗口底部附近的选项卡名称
  2. select View Code - this brings up a VBE window 选择查看代码 - 这会打开一个VBE窗口
  3. paste the stuff in and close the VBE window 粘贴内容并关闭VBE窗口

If you have any concerns, first try it on a trial worksheet. 如果您有任何疑虑,请先在试用工作表上试用。

If you save the workbook, the macro will be saved with it. 如果保存工作簿,宏将与其一起保存。 If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx 如果您在2003年之后使用的是Excel版本,则必须将文件另存为.xlsm而不是.xlsx

To remove the macro: 要删除宏:

  1. bring up the VBE windows as above 如上所述调出VBE窗口
  2. clear the code out 清除代码
  3. close the VBE window 关闭VBE窗口

To learn more about macros in general, see: 要了解有关宏的更多信息,请参阅:

http://www.mvps.org/dmcritchie/excel/getstarted.htm http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

To learn more about Event Macros (worksheet code), see: 要了解有关事件宏(工作表代码)的更多信息,请参阅:

http://www.mvps.org/dmcritchie/excel/event.htm http://www.mvps.org/dmcritchie/excel/event.htm

Macros must be enabled for this to work! 必须启用宏才能使其正常工作!

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

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