• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to popoulate multioption listbox from another listbox using vlookup?

Kiran212

New Member
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...
 
Hi, Kiran212!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the three first green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about your question...


Give a look at this file:

http://chandoo.org/forums/topic/data-validation-list-automatically-shows-the-first-item-in-the-list


Is that what you're looking for?


Regards!
 
Back
Top