Alan Treanor
Alan Treanor

Reputation: 159

if combo box is array value then populate alternative combo box VBA

I have 2 combo boxes on my userform if combo box 1 states 'Germany Home Shopping' if gives the following array

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

I also want to do it the opposite where if the value is one of the array answers in combobox 2 then it will put Germany Home Shopping in Combo Box 1. I thought this could be done like this?

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

But this doesn't seem to be working for me.

Thanks in advance :-) Al

Upvotes: 0

Views: 1801

Answers (1)

L42
L42

Reputation: 19727

You can try this:

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

Upvotes: 1

Related Questions