当前位置: 代码迷 >> Office >> excel怎么实现自动加某个单元格的数字
  详细解决方案

excel怎么实现自动加某个单元格的数字

热度:4228   发布时间:2013-02-26 00:00:00.0
excel如何实现自动加某个单元格的数字
举个例子:
A B
1 3
2 5
3 4
4 5

我现在要B1单元格中输入10,按回车后,B1的数字要变为13,就是说自动加前面的A1中的数字。
意思就是不管你在B列中输入什么数字,都要自动加前面A列的那个数字。该怎样实现?



------解决方案--------------------------------------------------------
这段代码加到sheet事件窗口里
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim x
If Target.Column = 2 Then
x = Target.Value
Application.EnableEvents = False
Target = x + Cells(Target.Row, 1).Value
Application.EnableEvents = True
End If
End Sub
  相关解决方案