Suppose I have a ComboBox in Excel VBA with the following sorts of info:
1234 apples
2345 pears
2367 oranges
I want the user to be able to
So first to give some context to this answer. SectorDropDown1_1 (which is part of a form) is a drop down list that is populated with the concatenated strings of a number value and a string value coming from a column J. In this context the _change() method responds to the user typing in values. I have 2 columns "R", and "S", in a spreadsheet "SectorSearch" that have separated the number and the text. So now if the user enters either the number or the text, then the appropriate value in the Drop Down list is selected. But here is the problem, my code sort of awkwardly jumps to the exact value and so I want to "smooth things out" so to speak so that after the user types more than 2 characters that match the appropriate value that this value is now selected and the drop down list shows the nearby values.
Option Explicit
Private Sub SectorDropDown1_1_Change()
Dim i As Long
Dim StringRange1 As String
Dim StringRange2 As String
Dim Stringrange3 As String
Dim LengthOfValue As Integer
Dim TotalSectorCodes As Integer
If SectorDropDown1_1.Value <> "" And Len(SectorDropDown1_1.Value) > 2 Then
TotalSectorCodes = Worksheets("SectorSearch").Range("J:J").Cells.SpecialCells(xlCellTypeFormulas).Count
LengthOfValue = Len(SectorDropDown1_1.Value)
For i = 2 To TotalSectorCodes
StringRange1 = "R" & CStr(i)
StringRange2 = "S" & CStr(i)
Stringrange3 = "J" & CStr(i)
Select Case SectorDropDown1_1.Value
Case Left(Worksheets("SectorSearch").Range(StringRange1).Value, LengthOfValue)
SectorDropDown1_1.Value = Worksheets("SectorSearch").Range(Stringrange3).Value
Exit For
Case Left(Worksheets("SectorSearch").Range(StringRange2).Value, LengthOfValue)
SectorDropDown1_1.Value = Worksheets("SectorSearch").Range(Stringrange3).Value
Exit For
Case Else
'...
End Select
Next i
End If
End Sub