excel单元格数据互相关联 - 爱问答

(爱问答)

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实现

函数操作还是很方百安达

相关标签:excel

下一篇:请问你找到在武术图片上添加带箭头的线条的方法了吗?

上一篇:桌面移到D盘后,怎样恢复到C盘

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?