【发布时间】:2018-03-24 09:06:13
【问题描述】:
我以两种方式链接多个单元格,这意味着如果我更改一个,另一个将更新,反之亦然。 此代码适用于两个单元格
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$4" Then
'Application.EnableEvents = False
Sht_input.Range("E4").Value = Sht_input.Range("B4").Value
'Application.EnableEvents = True
End If
If Target.Address = "$E$4" Then
'Application.EnableEvents = False
Sht_input.Range("b4").Value = Sht_input.Range("e4").Value
'Application.EnableEvents = True
End If
End Sub
现在,当我尝试链接三个单元格时,代码进入不定式循环
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$4" Then
'Application.EnableEvents = False
Sht_input.Range("E4").Value = Sht_input.Range("B4").Value
Sht_input.Range("h4").Value = Sht_input.Range("B4").Value
'Application.EnableEvents = True
End If
If Target.Address = "$E$4" Then
'Application.EnableEvents = False
Sht_input.Range("b4").Value = Sht_input.Range("e4").Value
Sht_input.Range("h4").Value = Sht_input.Range("e4").Value
'Application.EnableEvents = True
End If
If Target.Address = "$H$4" Then
'Application.EnableEvents = False
Sht_input.Range("b4").Value = Sht_input.Range("H4").Value
Sht_input.Range("e4").Value = Sht_input.Range("H4").Value
'Application.EnableEvents = True
End If
End Sub
我试图调试,但我不明白为什么即使不再选择目标单元格,它也会回到“if”。谁能帮帮我?
【问题讨论】:
标签: excel vba infinite-loop