Combo Box in User Form not retaining the value selected

Nevermore

New Member
Joined
Sep 12, 2013
Messages
12
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.

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
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
If you reset or populate the combobox then you'll lose the selection.

Try setting the selection again after you've repopulated.
Code:
ComboBox1.Value =   MyText
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,499
Members
449,089
Latest member
Raviguru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top