Consulting

Results 1 to 13 of 13

Thread: Two Combo Boxes Active Control in the same sheet affecting each other

  1. #1
    VBAX Regular
    Joined
    Nov 2016
    Posts
    15
    Location

    Two Combo Boxes Active Control in the same sheet affecting each other

    Hi guys,

    I have encountered this problem:

    I'm trying to put two ComboBoxes in Sheet1, which are supposed to search and return information from two individual lists that are put in Sheet2 and Sheet3, respectively, according to the keyword I key in.

    However, they are affecting each other. If I put keywords in ComboBox1 I will get the right return as expected. Then I move on to use ComboBox2, but when I start typing anything into the ComboBox2, while it is still doing the search, I can't see it's returned drop down list, instead, the drop down list of my first search in ComboBox1 will show again. Vise versa, if I start from using ComboBox2 first, the same thing happen when I use ComboBox1.

    Here's the codes I use for these two comtrols:

    Private Sub ComboBox1_Change()
    ComboBox1.ListFillRange = "List1"
    Me.ComboBox1.DropDown
    End Sub
    
    
    Private Sub ComboBox2_Change()
    ComboBox2.ListFillRange = "List2"
    Me.ComboBox2.DropDown
    End Sub
    Please help.


    Thanks in advance.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    See if this helps
    Private Sub ComboBox1_Change() 
    Application.EnableEvents = False
    
        ComboBox1.ListFillRange = "List1" 
        Me.ComboBox1.DropDown 
    
    Application.EnableEvents = True
    End Sub 
     
     
    Private Sub ComboBox2_Change() 
    Application.EnableEvents = False
    
        ComboBox2.ListFillRange = "List2" 
        Me.ComboBox2.DropDown 
    
    Application.EnableEvents = True
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Nov 2016
    Posts
    15
    Location
    Thanks for helping.

    Seems the problem still exists.

    I have attach the file here. If you use any of the two ComboBoxes to do a search, leave the result without deleting it, and then do another search using another ComboBox, you'll see what happen.
    Attached Files Attached Files

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I am using Excel 2002, so I lose some information when I open an xlsm file. Sorry. I can't help.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Regular
    Joined
    Nov 2016
    Posts
    15
    Location
    Thank you.

    Anyone else please help.

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I did notice that "List1" and "List2" are not Ranges. This might be the problem.

    Also, you cannot set the initial value of a Control's List with that controls Change sub. There has to be something in the Control to change in order to run the Change sub.



    Can you say exactly what you are trying to accomplish.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Regular
    Joined
    Nov 2016
    Posts
    15
    Location
    Hi SamT,

    Those two ComboBoxes are supposed to work as search engine, something like Google. As you type in anything, it should detect what you have typed in and give you a list of options to choose from. As you have chosen any of those suggested options, it'll then pull that particular result.
    Also those two boxes are placed in the cells that they are linked to. You can move them somewhere else.
    Sheet "List1" and "List3" are serving as data base here. The highlighted columns are the ones actually being use. From the left of the highlighted columns, the first one contains the actual data, and the second and third ones work as filters and supposed to change according to what has been entered in the ComboBoxes. The third column would be the final list of options returned to the CoboBoxes in the form of a drop down list for the user to choose best fit result.

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    ComboBox Lists can be Ranges or Arrays, But not the results of Formulas. The Names in your workbook show that "List1" and "List2" are formulas.


    A VBA Function can return an array or a Range Address.

    If you want to start with a Listless ComboBox, use the Exit Event sub, then pass the typed in .Value to a Function that returns an Array of the List Items

    Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    
    With ComboBox1
    If .ListCount = 0 Then
    Cancel = True
    .List = GetListitems(.Value)
    .SetFocus
    
    Else
    'do something else
    End If
    End With
    
    End Sub
    
    Private Function GetListitems(Value_NotUsedIn_ThisDemo) As Variant
    GetListitems = Array("Item1", "Item2")
    End Function
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  9. #9
    VBAX Regular
    Joined
    Nov 2016
    Posts
    15
    Location
    Both List1 and List2 are defined in Name Manager.

    Still need help.

  10. #10
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.

    The Names in your workbook show that "List1" and "List2" are formulas.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  11. #11
    VBAX Regular
    Joined
    Nov 2016
    Posts
    15
    Location
    Thanks for your help.

    Anyone else have any idea?

    The problem now is if I delete one of these two ComboBoxes, only leave one, it works just fine.
    When I put two in the same sheet, they kinda interfere each other.

  12. #12
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    How can somebody help you when

    You refuse to listen?

    good bye and good luck. Happy coding.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  13. #13
    VBAX Regular
    Joined
    Nov 2016
    Posts
    15
    Location
    I really have no idea why you started yelling and jumped into the conclusion about me refusing to listen. I meant, basically this is what I'm here for.
    Anyway still thank you for your input.

    I'm actually trying to build something to use in my work, so really do not have time participate any kind of arguing.
    I was simply saying that knowing List1 and List2 having formulas neither answer my question about why two Comboboxes can't be in the same sheet because one single Combobox works just fine, nor did it tell me what to do next to solve the trouble.
    My logic is if having not defined range is the cause of the problem, then why one Combobox works?
    I do define both of them in formula manager and base on my understanding this way they are both set as range. If I'm wrong, I need some help to make it right, given that this is what causes the problem.

    I appreciate your time and patience. And I do hope to see different input as it's been days and the same problem still remains unsolved.

Posting Permissions

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