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.
Bookmarks