+ Reply to Thread
Results 1 to 8 of 8

ComboBox Filter, search with partial text improvement

Hybrid View

  1. #1
    Registered User
    Join Date
    04-20-2020
    Location
    Netherlands
    MS-Off Ver
    excel 2016
    Posts
    36

    ComboBox Filter, search with partial text improvement

    Hello there,

    I've made a combobox with an filter to search for partial matched values in my database. This is the code i use:
    Private Sub ComboBox1_Change()
    Call OptimizeCode_Begin
     
     Dim myVal As String, i As Long, ii As Long
    
        With Me.ComboBox1
            If .Text = "" Then
                .List = myList
            Else
                myVal = .Text
                For i = .ListCount - 1 To 0 Step -1
                    If Not UCase$(.List(i, 3)) Like "*" & UCase$(myVal) & "*" Then .RemoveItem (i)
                Next
            End If
        End With
    
     Call OptimizeCode_End
     
    End Sub
    There is one problem. When i start typing with the dropdown list expanded, and press a few letters, it does not remove the last item in the list. Now i get a list of matching strings, but there is still one value at the bottum of the list stuck, when its supposed to be deleted. I recon its because you take 1 from the listcount. But without this part, the code does not work.

    It looks like this:

    I would be really gratefull if someone could help me.
    Attached Images Attached Images

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,410

    Re: ComboBox Filter, search with partial text improvement

    I have this code stored in my useful box.
    It seems to work in all circumstances.
    Attached file.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    04-20-2020
    Location
    Netherlands
    MS-Off Ver
    excel 2016
    Posts
    36

    Re: ComboBox Filter, search with partial text improvement

    Quote Originally Posted by torachan View Post
    I have this code stored in my useful box.
    It seems to work in all circumstances.
    Attached file.
    i have troubles implementing it in my program. Thanks though for the example. Is there any way i can adjust my excisting code to work propperly?

  4. #4
    Registered User
    Join Date
    04-20-2020
    Location
    Netherlands
    MS-Off Ver
    excel 2016
    Posts
    36

    Re: ComboBox Filter, search with partial text improvement

    Quote Originally Posted by torachan View Post
    I have this code stored in my useful box.
    It seems to work in all circumstances.
    Attached file.
    Hey man,

    I've just looked into your program one more time. I manged to make it work! Thx alot for the code. Yet there is one problem i mentioned to you before, in the other thread.
    When i search for a product where there is two of with the same name. So for example "speakers" one with id 9 and the other with id 10. It will Always select the one with id nr 9 as it finds it first in the list.
    In de attachment i've put the new code with the (mostly) working combobox. I hope you could tell me where i am going wrong.

    Anyways, still thx for your time.

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,410

    Re: ComboBox Filter, search with partial text improvement

    I can not replicate your code without the two missing 'calls'

  6. #6
    Registered User
    Join Date
    04-20-2020
    Location
    Netherlands
    MS-Off Ver
    excel 2016
    Posts
    36

    Re: ComboBox Filter, search with partial text improvement

    the call is just for optimisation. but here is the full workbook. Hope this clarifies.

  7. #7
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,410

    Re: ComboBox Filter, search with partial text improvement

    The filter is working correctly - what do you think is wrong.

  8. #8
    Registered User
    Join Date
    04-20-2020
    Location
    Netherlands
    MS-Off Ver
    excel 2016
    Posts
    36

    Re: ComboBox Filter, search with partial text improvement

    If you selected an item with the same name as another item(but with different ID), it would always select the first item of those two. Even if the second one was selected.
    This is because i was looking for a partial match in a string by checking each item one by one. As soon as it found a match it would display the match. Even though you might have selected an item further down the list. I fixed this by checking for the list index instead of the name as this is unique.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Partial search in combobox with name range
    By frankytheman in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-19-2020, 11:43 PM
  2. Search and Match partial text string to full text and return a value
    By homa5424 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-09-2017, 10:52 AM
  3. Replies: 15
    Last Post: 07-27-2017, 08:18 AM
  4. Filter search with combobox option
    By matt-43 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-26-2016, 05:57 AM
  5. search partial text
    By shaifshahin in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-14-2016, 12:17 PM
  6. Partial text search
    By dawsexcel in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 07-23-2014, 12:50 PM
  7. Replies: 2
    Last Post: 02-06-2014, 09:52 AM

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