如何在一个单元格中求和? [英] How to make a cumulative sum in one cell?
问题描述
我想将一个单元格中的值累加到附近的单元格中.当我键入单元格时,它应该对值求和.例如,每当我向A1输入新值时,都应将B1单元格的总和相加.有可能吗?
I would like the sum the values in one cell into nearby cell cumulatively. It should sum the values, when I typed in the cell. For example whenever I enter a new value to A1 it should sum the total at B1 cell. Is that possible ?
我试图总结一下公式
=B1+A1
但是我遇到了递归函数错误.
but i get recursive function error.
推荐答案
在工作表代码区域中放置以下事件宏:
Place 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
[B1] = [B1] + [A1]
End Sub
由于它是工作表代码,因此非常易于安装和自动使用:
Because it is worksheet code, it is very easy to install and automatic to use:
- 右键单击Excel窗口底部附近的标签名称
- 选择查看代码-这将打开一个VBE窗口
- 将内容粘贴并关闭VBE窗口
如果您有任何疑问,请先在试用工作表上尝试一下.
If you have any concerns, first try it on a trial worksheet.
如果保存工作簿,则宏将随其一起保存.如果要在2003年以后使用Excel版本,则必须保存该文件为.xlsm而不是.xlsx
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
要删除宏,请执行以下操作:
To remove the macro:
- 如上所述调出VBE窗口
- 清除代码
- 关闭VBE窗口
要全面了解有关宏的更多信息,请参见:
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
和
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
必须启用宏才能使其正常工作!
这篇关于如何在一个单元格中求和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!