我目前有三个组合框(comboBox2,comboBox3,comboBox4)。 ComboBox2.ListFillRange和ComboBox3.ListFillRange当前链接到命名范围。根据ComboBox2和ComboBox3中的选择,ListFillRange对于ComboBox4将是不同的,即它查看不同的名称范围。
lnkArr
当我选择"内部"对于ComboBox2和" Breach"对于ComboBox3,我获得了ComboBox4所需的ListFillRange。但是,如果我然后选择"外部"对于ComboBox2并将ComboBox3保留为" Breach"我没有在ComboBox4中获得预期的ListFillRange用于"外部" - "违反"组合,我必须重新选择" Breach"得到这个。任何人都知道如何在重新选择一个并离开另一个时自动更新它?
答案 0 :(得分:0)
这是因为您只有ComboBox3_Change()
事件处理程序,只有在ComboBox3
发生更改时才会触发。
你必须帮助一个必须做同样工作的ComboBox2_Change()
事件处理程序
因此您可以添加sub
以由任一事件处理程序调用
而且你遇到了以下问题:
Else: ComboBox2.Value = "External" And ComboBox3.Value = "Error"
ComboBox4.ListFillRange = "=External_Error"
End If
因为它会导致:
Else
ComboBox2.Value = "External" And ComboBox3.Value = "Error"
ComboBox4.ListFillRange = "=External_Error"
End If
因此在行中出错:
ComboBox2.Value = "External" And ComboBox3.Value = "Error"
对于工作表代码窗格中代码的上述内容,可以是:
Option Explicit
Private Sub ComboBox2_Change()
Application.EnableEvents = True
Call CheckComboBoxes
End Sub
Private Sub ComboBox3_Change()
Application.EnableEvents = True
Call CheckComboBoxes
End Sub
Sub CheckComboBoxes()
If ComboBox2.Value = "Internal" And ComboBox3.Value = "Breach" Then
ComboBox4.ListFillRange = "=Internal_Breach"
ElseIf ComboBox2.Value = "Internal" And ComboBox3.Value = "Error" Then
ComboBox4.ListFillRange = "=Internal_Error"
ElseIf ComboBox2.Value = "External" And ComboBox3.Value = "Breach" Then
ComboBox4.ListFillRange = "=External_Breach"
ElseIf ComboBox2.Value = "External" And ComboBox3.Value = "Error" Then
ComboBox4.ListFillRange = "=External_Error"
ElseIf ComboBox2.Value = "External" And ComboBox3.Value = "Error" Then
ComboBox4.ListFillRange = "=External_Error"
End If
End Sub
可以缩短为:
Option Explicit
Private Sub ComboBox2_Change()
Application.EnableEvents = True
Call CheckComboBoxes
End Sub
Private Sub ComboBox3_Change()
Application.EnableEvents = True
Call CheckComboBoxes
End Sub
Sub CheckComboBoxes()
ComboBox4.ListFillRange = ComboBox2.Value & "_" & ComboBox3.Value
End Sub