Hi All,
I am working on a form. I am using listboxes with muti select option. Listbox2 is auto populated from first row of sheet i.e. Region.
If you select a region(from listbox2), the relevant Country should display in Listbox3. I done vlookup for this, but only first value is coming. I think a loop is required.
Please let me figure out the mistake.
My code:
Private Sub ListBox2_Change()
Dim i As Integer
If ListBox2.ListIndex = -1 Then Exit Sub
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) = True Then
ListBox3.AddItem (Application.VLookup(ListBox2.List(i), Sheets("Sheet1").Range("A:B"), 2, False))
End If
Next i
End Sub
Also if we click same Region for a second time, the country names relevant to it should be removed.
Thanks in advance...
I am working on a form. I am using listboxes with muti select option. Listbox2 is auto populated from first row of sheet i.e. Region.
If you select a region(from listbox2), the relevant Country should display in Listbox3. I done vlookup for this, but only first value is coming. I think a loop is required.
Please let me figure out the mistake.
My code:
Private Sub ListBox2_Change()
Dim i As Integer
If ListBox2.ListIndex = -1 Then Exit Sub
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) = True Then
ListBox3.AddItem (Application.VLookup(ListBox2.List(i), Sheets("Sheet1").Range("A:B"), 2, False))
End If
Next i
End Sub
Also if we click same Region for a second time, the country names relevant to it should be removed.
Thanks in advance...