[英]How do I make two cells dependent on one another without circular error?
In Excel 2013, I have cells A1, A2, and A3 along with B1, B2, and B3. 在Excel 2013中,我具有单元格A1,A2和A3以及B1,B2和B3。 Column A is a yearly calculation and Column B is a weekly calculation. A列是年度计算,B列是每周计算。
For example, if the user updates A1 (eg, 5200
), I want to auto-update B1 (eg, 100
). 例如,如果用户更新A1(例如5200
),我想自动更新B1(例如100
)。 If the user updates B1 (eg, 50
), I want to auto-update A1 (eg, 2600
). 如果用户更新B1(例如50
),我想自动更新A1(例如2600
)。 Likewise for A2-B2 and A3-B3. 对于A2-B2和A3-B3同样。
When I try to monitor both, it creates a circular issue and Excel crashes. 当我尝试监视两者时,它会产生一个循环问题,并且Excel崩溃。
Don't use formula at all then. 那就不要使用公式了。 Use a _Change
event like this: 使用_Change
事件,如下所示:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("A:B")) Is Nothing Then Exit Sub
Application.EnableEvents = False 'Prevent infinite looping
If Target.Column = 1 Then
'User has changed something in column A:
Target.Offset(0, 1).Value = Target / 52
Else
'User has changed something in column B:
Target.Offset(0, -1).Value = Target * 52
End If
Application.EnableEvents = True
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.