Consulting

Results 1 to 3 of 3

Thread: Solved: 3 mulitilink comboboxes

  1. #1
    VBAX Regular
    Joined
    Sep 2010
    Posts
    40
    Location

    Solved: 3 mulitilink comboboxes

    hi im new here, and new to vba for excel also,
    im making a project on which i have multiple comboboxes which are link to the previous combobox(eg combobox1 link to combobox2 which is link to combobox 3 and so on.) and that the value of the later comboboxes are dependent on the previous.

    on this example i shortened the list of comboboxes to two.

    i have a button called Produce, bringin userform1 with 2 comboboxes and 2 command button.
    i need a code that generates value of combobox 2 if i selected a value to combobox1.

    an example is attached...

    btw i tried if and else and case select, it didnt work or theres something wrong with my code.

    i appreciate your help. thanks in advance.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Option Explicit

    Private Sub cmdCancel_Click()
    'Unload the userform
    Unload Me
    End Sub

    Private Sub cmdOkay_Click()
    'Verify that an item was selected
    Dim strname As String
    If Me.ComboBox1.BoundValue & Me.ComboBox2.BoundValue _
    = vbNullString Then
    MsgBox "You did not choose an item!", vbOKOnly

    Exit Sub
    Else
    MsgBox "You choose " & Me.ComboBox1.Text & ComboBox2.Text
    Sheets("sheet1").Range("j1").Value = ComboBox1.Text
    Sheets("sheet1").Range("k1").Value = ComboBox2.Text
    End If
    Unload Me
    End Sub

    Private Sub ComboBox1_Change()

    With Me.ComboBox2

    .Clear

    Select Case ComboBox1.Value

    Case "TUG"
    .AddItem ("a")
    .AddItem ("b")
    .AddItem ("c")

    Case "MLA"
    .AddItem ("1")
    .AddItem ("2")
    .AddItem ("3")
    End Select
    End With
    End Sub

    Private Sub UserForm_Initialize()
    'Load the combobox with a variety of household pets
    With Me.ComboBox1
    .AddItem ("TUG")
    .AddItem ("MLA")
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Sep 2010
    Posts
    40
    Location
    yay thanks XLD... your code does it well... now i can follow this fir my multiple comboboxes, thanks thanks...
    btw, sorry for the late reply...

Posting Permissions

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