Private Sub ComboBox3_Change()
Set ws = ThisWorkbook.Worksheets("Formula")
ws.Activate
Dim DisableUFEvents As Boolean
Dim cText As String, sheetRow As Variant
Dim WordOptions As Variant
If DisableUFEvents Then Exit Sub
With ComboBox3
cText = .Text
WordOptions = MatchingWords(cText)
If 0 < UBound(WordOptions) Then
ComboBox3.List = WordOptions
If .ListCount = 1 Then
DisableUFEvents = True
.Text = .List(0)
.SelStart = Len(cText)
.SelLength = 100
DisableUFEvents = False
Else
.DropDown
End If
End If
End With
Dim i As Long, Lastrow As Long
Lastrow = Sheets("Formula").Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Lastrow
If Sheets("Formula").Cells(i, "A").Value = (Me.ComboBox3) Or _
Sheets("Formula").Cells(i, "A").Value = Val(Me.ComboBox3) Then
Me.TextBox2 = Sheets("Formula").Cells(i, "B").Value
End If
Next
End Sub
Private Sub ComboBox3_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim DisableUFEvents As Boolean
DisableUFEvents = (KeyCode = vbKeyBack)
End Sub
Function WordsRange() As Range
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Formula")
ws.Activate
With Range("A:A")
Set WordsRange = Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
End With
End Function
Function MatchingWords(ByVal StartOfWord As String) As Variant
Set ws = ThisWorkbook.Worksheets("Technical Attribute")
ws.Activate
Dim DisableUFEvents As Boolean
Dim oneCell As Range, Pointer As Long
Dim Result() As String
StartOfWord = LCase(StartOfWord)
ReDim Result(1 To WordsRange.Cells.Count)
For Each oneCell In WordsRange
If LCase(oneCell.Text) Like StartOfWord & "*" Then
Pointer = Pointer + 1
Result(Pointer) = oneCell.Text
End If
Next oneCell
If 0 = Pointer Then
ReDim Result(0 To 0)
Else
ReDim Preserve Result(1 To Pointer)
End If
MatchingWords = Result
End Function
Private Sub UserForm_Initialize()
ComboBox1.ShowDropButtonWhen = fmShowDropButtonWhenNever
End Sub