Excel VBA Target.address worksheet.onchange无限循环

我有单元格A1,单元格B1和单元格C1,我需要检查值是否由用户或VBA在A1中更改。 whith out如果Target.Address A1上的声明造成无限循环

Private Sub Worksheet_Change(ByVal Target As range) If Target.Address = B1 or Target.Address = C1 Then If IsEmpty(Cell("B1")) then Cell("A1").value = "Enter value" If IsEmpty(Cell("C1")) then Cell("A1").value = "" Else Cell("A1").value = "=C1/B1" End IF End IF End IF If Target.Address = A1 IF "changed by user typing" Then Cell("B1").value = "" Cell("C1").value = "" Else End IF End IF End Sub 

如何确定什么目标是由用户而不是从VBA更改?

我怀疑你想要这样的东西:

 Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("A1")) Is Nothing Then Application.EnableEvents = False Range("B1:C1").Value = "" Application.EnableEvents = True ElseIf Not Intersect(Target, Range("B1:C1")) Is Nothing Then Application.EnableEvents = False If IsEmpty(Range("B1")) Then Range("A1").Value = "Enter value" ElseIf IsEmpty(Range("C1")) Then Range("A1").Value = "" Else Range("A1").Value = "=C1/B1" End If Application.EnableEvents = True End If End Sub