(急!)excel 中多单元格关联计算!

来源:百度知道 编辑:UC知道 时间:2024/06/02 00:57:36
在excel 中,有三个单元格,a1 b1 c1 ,我只要在C1中输入数字2,A1就能2,接着C1单元格数字为0。如果再接着输入5,那么A1为5+2。B2同时记录先前A1的数据2。最后C1的数据清0。也就是只要改变C1的数据,A1就会变化。好何用VBA处理。

change事件中处理就可以。给你个示例代码,在C1中输入数字你可以试验一下:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo err
If Target.Row <> 1 Or Target.Column <> 3 Then Exit Sub
If Cells(1, 3).Value = "" Then Exit Sub
Cells(2, 2).Value = Cells(1, 1)
Cells(1, 1).Value = CLng(Cells(1, 1).Value) + CLng(Cells(1, 3))
Cells(1, 3).Value = ""
err:
End Sub

用宏可以实现,一定要用VBA?。