【问题标题】:if combo box is array value then populate alternative combo box VBA如果组合框是数组值,则填充替代组合框 VBA
【发布时间】:2014-09-22 19:08:22
【问题描述】:

如果组合框 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

但这似乎对我不起作用。

提前致谢 :-) 铝

【问题讨论】:

  • 更改您的 if 语句以循环遍历数组测试,如 for each ele in Array(x, y ,z): if combobox2.selecteditem = ele then: combobox1.value = "Germany etc..": exit for: end if: Next
  • @Cor_Blimey 我收到一个编译错误,说明方法或数据成员未找到?

标签: arrays vba excel combobox


【解决方案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

【讨论】:

  • 这确实将 combobox1 更新到相关频道,但随后会将 combobox2 变回空白。
  • @AlanTreanor 其实我想知道你为什么要这样做。如果您在 ComboBox1 中有一个 Change_Event 来填充 ComboBox2 列表,它不会特别累加。所以基本上它是 ComboBox2 列表基于 ComboBox1 或反之亦然。
猜你喜欢
  • 1970-01-01
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-22
相关资源
最近更新 更多