
Originally Posted by
nordicdust
What I relly would like:
- A Userform where I would like a way to type in the textBox while the ListBox shows the values from a Table with Zip code in Col 1 and City in Col 2.
- While typing in TextBox the ListBox should only show matching possibilities.
- I would like the option of searching by either Zip Code or City.
- The ListBox should show Zip Code and Matching City (As in merged Cells on Sheet)
- A way to Select the value from the ListBox to the TextBox.
Try this:
Notes:
1. searching in textbox is case insensitive, try typing '72 a'.
2. to transfer value from listbox to textbox use doubleclick.
Option Explicit
Public flag As Boolean
Private Sub Cmbt_OK_Click()
Unload UF_INDTASTSAGSINFORMATION
End Sub
Private Sub Listbox_RESULTAT_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
flag = True
Txb_POSTNR_BY.Value = Me.Listbox_RESULTAT.Value
End Sub
Private Sub Txb_POSTNR_BY_Change()
Dim a, vList
Dim firstAddress As String
Dim d As Object, i As Long
If flag = True Then
flag = False
Exit Sub
End If
vList = ThisWorkbook.Worksheets("ENGINE").Range("Q2:Q159").Value
If Txb_POSTNR_BY.Value <> "" Then
Set d = CreateObject("scripting.dictionary")
For i = LBound(vList) To UBound(vList)
If LCase(vList(i, 1)) Like "*" & Replace(LCase(Txb_POSTNR_BY.Value), " ", "*") & "*" Then
d(vList(i, 1)) = 1
End If
Next
Me.Listbox_RESULTAT.List = d.keys
If d.Count = 0 Then MsgBox "No Match Found"
Else
Me.Listbox_RESULTAT.List = vList
End If
End Sub
Private Sub UserForm_Initialize()
Listbox_RESULTAT.List = ThisWorkbook.Worksheets("ENGINE").Range("Q2:Q159").Value
flag = False
End Sub
Bookmarks