I wanted to use ListBox so that I can select the entry rather than TextBox

半世苍凉 提交于 2019-12-02 08:00:41

Assuming the name of the listbox is ListBox1 then you may try something like this...

Private Sub txtNumber_Change()
Dim mySheet As Worksheet    'declaring mySheet as the Worksheet...
Dim x, dict
Dim i As Long
Dim cnt As Long
Set mySheet = Sheets("Sheet1")
ListBox1.Clear
x = mySheet.Range("A1").CurrentRegion.Value
Set dict = CreateObject("Scripting.Dictionary")
If Application.CountIf(mySheet.Columns(2), txtNumber.Value) > 0 Then
    For i = 2 To UBound(x, 1)
        If x(i, 2) = Val(txtNumber.Value) Then
            dict.Item(x(i, 1)) = ""
        End If
    Next i
    ListBox1.List = dict.keys
Else
    ListBox1.AddItem "Match not found"
End If
End Sub
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!