Hi,
I am trying to prepare a User Form with Combo Box that will dynamically change the list as and when the user types.
The problem right now is when the user selects the item from the list, Combo Box is showing blank.
Below is the code it runs everything fine apart from the problem I stated in the above line.
I am trying to prepare a User Form with Combo Box that will dynamically change the list as and when the user types.
The problem right now is when the user selects the item from the list, Combo Box is showing blank.
Below is the code it runs everything fine apart from the problem I stated in the above line.
Code:
Private Sub ComboBox1_Change()
Dim LastRow, LastRow1, Chk, i, SearchText, Cell_Value, Temp_Value
Static MyText, FinalText, Control
Chk = False
LastRow = ThisWorkbook.Sheets("Unique List").Cells(Rows.Count, 1).End(xlUp).Row
LastRow1 = ThisWorkbook.Sheets("Temp").Cells(Rows.Count, 1).End(xlUp).Row
If LastRow1 > 2 Then
ThisWorkbook.Sheets("Temp").Range("A2:A" & LastRow1).ClearContents
ElseIf Not ThisWorkbook.Sheets("Temp").Range("A2").Value = "" Then
ThisWorkbook.Sheets("Temp").Range("A2").ClearContents
End If
For i = 2 To LastRow
MyText = Me.ComboBox1.Value
SearchText = ThisWorkbook.Sheets("Unique List").Cells(i, 1).Value
Chk = InStr(1, SearchText, MyText, vbTextCompare)
If Chk Then
LastRow1 = ThisWorkbook.Sheets("Temp").Cells(Rows.Count, 1).End(xlUp).Row + 1
ThisWorkbook.Sheets("Temp").Cells(LastRow1, 1).Value = ThisWorkbook.Sheets("Unique List").Cells(i, 1).Value
End If
Chk = False
Next i
On Error Resume Next
ActiveWorkbook.Names("ItemDescription").Delete
On Error GoTo 0
LastRow1 = ThisWorkbook.Sheets("Temp").Cells(Rows.Count, 1).End(xlUp).Row
ThisWorkbook.Names.Add Name:="ItemDescription", RefersToR1C1:= _
"=Temp!R2C1:R" & LastRow1 & "C1"
ComboBox1.RowSource = "ItemDescription"
ComboBox1.DropDown
FinalText = Me.ComboBox1.Value
End Sub