excel单元格数据互相关联
A1单元格加B1单元格等于C1单元格。正常是在C1中输入=A1+B1。能不能实现在这三个单元格中输入其中两个,然后自动得出另外一个的值呢?
举例:在A1输入1,B1输入2,C1就自动等于3,在A1输入1,C1输入3,B1就自动等于2,然后在B1输入2,C1输入3,A1就自动等于1。
可以利用VBA:
1 借助D1为辅助单元格,先输入0;
2 在当前表单的VBA对象页面加入以下代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 And Target.Column < 4 Then
Cells(1, 4) = Abs(1 - Cells(1, 4))
If Cells(1, 4) = 1 Then GoTo 100
If Target.Column = 1 Then
If Cells(1, 2) = "" Then
Cells(1, 2) = Cells(1, 1) + Cells(1, 3)
Else
Cells(1, 3) = Cells(1, 1) + Cells(1, 2)
End If
ElseIf Target.Column = 2 Then
If Cells(1, 1) = "" Then
Cells(1, 1) = Cells(1, 2) + Cells(1, 3)
Else
Cells(1, 3) = Cells(1, 1) + Cells(1, 2)
End If
Else
If Cells(1, 1) = "" Then
Cells(1, 1) = Cells(1, 2) + Cells(1, 3)
Else
Cells(1, 2) = Cells(1, 1) + Cells(1, 3)
End If
End If
End If
100
End Sub
注意:比如变更了B2,如果此时A1不为空,则C1=A1+B1,否则A1=B1+C1;其他情形也依循此原则;
其实这是一种循环应用,在excel中可能应用VBA实现
函数操作还是很方百安达