Results 1 to 8 of 8

Help with VBA code for ActivX combo for partial string search and item selection

Threaded View

  1. #1
    Registered User
    Join Date
    10-03-2021
    Location
    Perth Australia
    MS-Off Ver
    Office 365
    Posts
    4

    Help with VBA code for ActivX combo for partial string search and item selection

    Hi All

    This is my 1st post and I am just beginning with VBA code. I have set up an ActiveX combo box linked to an item list range "CATS" (expenditure categories) and the code at present does autocomplete using the initial text entry in the combo box. I would like to change this to a dynamic text string search which will filter the drop down display list to input string matches (any position) from the items in "CATS". I then use the down arrow and then ENTER to make the selection as well as moving down to the next row for the next selection process.

    The code I have presently is;

     
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim str As String
    Dim cboTemp As OLEObject
    Dim ws As Worksheet
    Set ws = ActiveSheet
    On Error GoTo errHandler
    
    If Target.Count > 1 Then GoTo exitHandler
    
    Set cboTemp = ws.OLEObjects("TempCombo")
      On Error Resume Next
    If cboTemp.Visible = True Then
      With cboTemp
        .Top = 10
        .Left = 10
        .ListFillRange = ""
        .LinkedCell = ""
        .Visible = False
        .Value = ""
      End With
    End If
    
      On Error GoTo errHandler
      If Target.Validation.Type = 3 Then
        'if the cell contains a data validation list
        Application.EnableEvents = False
        'get the data validation formula
        str = Target.Validation.Formula1
        str = Right(str, Len(str) - 1)
        With cboTemp
          'show the combobox with the list
          .Visible = True
          .Left = Target.Left
          .Top = Target.Top
          .Width = Target.Width + 15
          .Height = Target.Height + 5
          .ListFillRange = "CATS"
          .LinkedCell = Target.Address
        End With
        cboTemp.Activate
        'open the drop down list automatically
        Me.TempCombo.DropDown
      End If
    
    exitHandler:
      Application.ScreenUpdating = True
      Application.EnableEvents = True
      Exit Sub
    errHandler:
      Resume exitHandler
    
    Private Sub TempCombo_KeyDown(ByVal _
            KeyCode As MSForms.ReturnInteger, _
            ByVal Shift As Integer)
        Select Case KeyCode
            Case 13 'Enter
                ActiveCell.Offset(0, 1).Activate
                Dim rng As Range
                Set rng = Range( _
                Cells(ActiveCell.Row + 1, ActiveCell.Column), _
                Cells(Rows.Count, ActiveCell.Column) _
                )
                rng.SpecialCells(xlCellTypeVisible).Cells(1).Select
                ActiveCell.Offset(0, -1).Activate
            Case Else
                'do nothing
        End Select
    End Sub
    
    
    End Sub
    Perhaps someone has written a code package that uses partial string matching in an ActiveX combo?

    The code I have presently has been taken from an online sample somewhere and I have tinkered with it a little - it works just fine for autocomplete list selections.

    I would really appreciate any help forum members can offer as I am stuck on this one.

    Cheers from an Aussie.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to search partial text string using INDEX?
    By joey1 in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 05-10-2018, 08:08 AM
  2. Search Similar item of Combo box
    By Chandria in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2018, 08:06 PM
  3. [SOLVED] VBA Countifs to search for partial string
    By arpirnat in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-23-2016, 05:01 PM
  4. Excel partial string search
    By lolceh in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-06-2015, 03:58 AM
  5. Search in a listbox on partial string as you type
    By Flyb in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-11-2015, 08:24 PM
  6. [SOLVED] VBA function to search partial string and return value
    By gorelordz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-28-2014, 11:48 AM
  7. [SOLVED] Vlookup, Match (Search or Find) partial string within string in a Cell
    By dluhut in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-28-2013, 12:40 PM

Tags for this Thread

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