Results 1 to 4 of 4

populate listbox based on selection in previous listbox

Threaded View

sarahng86 populate listbox based on... 10-28-2007, 10:38 AM
VBA Noob Welcome to the forum. ... 10-28-2007, 10:44 AM
Norie How would the values be... 10-28-2007, 01:37 PM
sarahng86 Hi, Thanks for the quick... 10-28-2007, 10:55 PM
  1. #1
    Registered User
    Join Date
    10-28-2007
    Posts
    6

    populate listbox based on selection in previous listbox

    Hi,
    I'm trying to populate a listbox based on the selection i made in the previous listbox,
    e.g. I'm selecting country in listbox1,
    state in listbox 2
    i want hotel names in listbox 3 to populate according to the states i've selected in listbox 2.
    i've used this code to do it so far-using dynamic named ranges, but im wondering if there is another way to do it?

     Private Sub lbdestination_Change()
    Sheet3.Range("B14").Value = Sheet3.lbdestination.Value
    'Get the currently selected item
                            
                 Select Case Sheet3.lbdestination.Value
    
                   'If Malaysia, set ListFillRange of Sheet3.lblocation
                   'to Sheet3.Column K.
                   Case "Malaysia"
                       Sheet3.lblocation.ListFillRange = "my"
                       
                   'If Singapore set ListFillRange of Sheet3.lblocation
                   'to Sheet3.Column L.
                   Case "Singapore"
                       Sheet3.lblocation.ListFillRange = "sg"
    
                   'If Cambodia, set ListFillRange of Sheet3.lblocation to
                   'Sheet3.Column M.
                   Case "Cambodia"
                       Sheet3.lblocation.ListFillRange = "cmb"
    
                   'If New Zealand, set ListFillRange of Sheet3.lblocation to
                   'Sheet3.Column N.
                   Case "New Zealand"
                       Sheet3.lblocation.ListFillRange = "nz"
                    
                    'If Indonesia, set ListFillRange of Sheet3.lblocation to
                   'Sheet3.Column O.
                   Case "Indonesia"
                       Sheet3.lblocation.ListFillRange = "indo"
                    End Select
    End Sub

    the code currently only works when the item in the listbox is clicked on, wondering if i can change the code such that if an item is ADDED to a particular listbox, the list for this item will automatically populate in the next listbox

    thanks !!
    Last edited by VBA Noob; 10-28-2007 at 10:44 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1