+ Reply to Thread
Results 1 to 5 of 5

Dependent Drop Down lists (multiple drop down)

  1. #1
    Registered User
    Join Date
    10-05-2004
    Posts
    18

    Dependent Drop Down lists (multiple drop down)

    Hi,

    I am a newbie to VBA.

    I am trying to create dependant dropdown lists based on four different fields.
    and am currently trying to make it so that I can have a list of options in one drop down list, and depending on what gets picked there, make it so that the
    options for the second drop down list correspond with the first. I found vb code (by Matt) on one of the forums but couldn't make it work.

    The screen shot of the excel file and the code are attached. I know it is full of mistakes. Hope someone can help me.


    PHP Code: 
    Private Sub CommandButton1_Click()
    Dim myLastRow As Integer

    Application
    .ScreenUpdating False

    Range
    ("A2").Select
    Selection
    .Sort Key1:=Range("A2"), Order1:=xlAscendingHeader:=xlYes_
        OrderCustom
    :=1MatchCase:=FalseOrientation:=xlTopToBottom

    ComboBox1
    .Clear
    ComboBox2
    .Clear
    myLastRow 
    Range("a65000").End(xlUp).Row
    Range
    ("A2").Select

    Do Until ActiveCell.Row myLastRow
        
    If ActiveCell.Value <> ActiveCell.Offset(-10).Value Then
            ComboBox1
    .AddItem ActiveCell.Value
        End 
    If
        
    ActiveCell.Offset(10).Select
    Loop
    Application
    .ScreenUpdating False

    End Sub

    Private Sub ComboBox1_Change()
    Dim myLastRow As Integer

    Application
    .ScreenUpdating False

    Range
    ("A2").Select
    Selection
    .Sort Key1:=Range("A2"), Key2:=Range("B2"), Order1:=xlAscendingOrder2:=xlAscendingHeader:=xlYes
    ComboBox2
    .Clear
    myLastRow 
    Range("a65000").End(xlUp).Row
    Range
    ("A2").Select
    Do Until ActiveCell.Value ComboBox1.Value
        ActiveCell
    .Offset(10).Select
    Loop

    Do Until ActiveCell.Value <> ComboBox1.Value
        
    If ActiveCell.Offset(01).Value <> ActiveCell.Offset(-11).Value _
            
    Or ActiveCell.Offset(00).Value <> ActiveCell.Offset(-10).Value Then
            ComboBox2
    .AddItem ActiveCell.Offset(01).Value
        End 
    If
        
    ActiveCell.Offset(10).Select
    Loop
    Application
    .ScreenUpdating False


    End Sub
    Private Sub ComboBox2_Change()
    Dim myLastRow As Integer

    Application
    .ScreenUpdating False

    Range
    ("A2").Select
    Selection
    .Sort Key1:=Range("A2"), Key2:=Range("B2"), Key3:=Range("C2"), Order1:=xlAscendingOrder2:=xlAscendingHeader:=xlYes
    ComboBox3
    .Clear
    myLastRow 
    Range("a65000").End(xlUp).Row
    Range
    ("A2").Select
    Do Until ActiveCell.Value ComboBox2.Value
        ActiveCell
    .Offset(10).Select
    Loop

    Do Until ActiveCell.Value <> ComboBox2.Value
        
    If ActiveCell.Offset(01).Value <> ActiveCell.Offset(-11).Value _
            
    Or ActiveCell.Offset(00).Value <> ActiveCell.Offset(-10).Value Then
            ComboBox2
    .AddItem ActiveCell.Offset(01).Value
        End 
    If
        
    ActiveCell.Offset(10).Select
    Loop
    Application
    .ScreenUpdating False


    End Sub
    Private Sub ComboBox3_Change()

    End Sub

    Private Sub ComboBox4_Change()

    End Sub 

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Can't see the screen shot, but perhaps you could attach a sample file that has data to match what you are trying to do. Include the code you have given, and give a scenario - say if you pick xxx from combobox1, then you would see yyy,zzzz,aaa in combobox2......


    rylo

  3. #3
    Registered User
    Join Date
    10-05-2004
    Posts
    18
    Hi Rilo,

    I am attaching the screen shot. I have 4 drop downs. To illustrate, if I select Fruit in drop down and Apple in drop down 2, I should only have two items in dropdown 3 (Golden & Natural), once I select one from dropdown 3, I should only have "Ontario" as available option in dropdown 4.

    This is what I want to achieve.

    Hope you can help.

    Thanks

    Jijy
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    See if the attached file gets you started.

    rylo
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-05-2004
    Posts
    18
    Hi Rylo,

    Thanks a lot for your help. Really appreciate the time & effort you took to help out.

    I am going to modify this a little bit and will come back to you if I have questions.

    Thanks once again.

    Jijy

+ Reply to Thread

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