如果组合框是数组值,则填充替代组合框VB​​A

时间:2014-09-21 18:57:23

标签: arrays excel vba excel-vba combobox

如果组合框1指出“德国家庭购物”,如果提供以下数组,我的用户表格上有2个组合框

If ComboBox1.Value = "Germany Home Shopping" Then
ComboBox2.List = Array("GER Singles ABE", "GER Singles CDF", "GER Small Cat ABE", "GER Small Cat CDF", "GER Small Cat All Zone", "GER Large Cat ABE", "GER Large Cat CDF", "GER Large Cat All Zone")
End If

我也想做相反的事情,如果值是组合框2中的数组答案之一,那么它将把德国家庭购物放在组合框1中。我认为这可以这样做吗?

If ComboBox2.List = Array("GER Singles ABE", "GER Singles CDF", "GER Small Cat ABE", "GER Small Cat CDF", "GER Small Cat All Zone", "GER Large Cat ABE", "GER Large Cat CDF", "GER Large Cat All Zone") Then
ComboBox1.Value = "Germany Home Shopping" 
End If

但这似乎对我不起作用。

提前致谢:-) 人

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

Dim mylist
mylist = Array("GER Singles ABE", "GER Singles CDF", "GER Small Cat ABE", _
         "GER Small Cat CDF", "GER Small Cat All Zone", "GER Large Cat ABE", _
         "GER Large Cat CDF", "GER Large Cat All Zone") 
If Not IsError(Application.Match(Me.ComboBox2.Value, mylist, 0)) Then
    Me.ComboBox1.Value = "Germany Home Shopping"
End If