so I have a userform with comboBox serving as a dynamic-search box.
The data needed to be searched is located in another workbook (1200+ rows). To avoid constant opening and closing of that data-workbook, I load it all into dictionary during form initialization.
Now my question is: is it possible to quickly filter out dictionary data (and update combobox), as user is typing or do I need to change my approach?
any help would be greatly appreciated.
here is the code I have so far:
Option Explicit
Private emplDict As Object
'all other constants and functions are declared in a separate module named "code"
Private Sub btnClose_Click()
Unload Me
End Sub
Private Sub comboSearch_Change()
Me.comboSearch.DropDown
End Sub
Private Sub UserForm_Initialize()
Dim xlWS As Worksheet
Dim xlWB As Workbook
Dim rng As Range
Dim lstRw As Long
Dim item As Variant
Application.Run "code.xlHelper", False ' turn off screen updating, alerts, events
Set emplDict = CreateObject("scripting.dictionary")
Set xlWB = Workbooks.Open(Filename:=SUB_PLANNING & EMPLOYEE_LIST)
Set xlWS = xlWB.Sheets("namen_werknemers")
With xlWS
lstRw = .Cells(Rows.Count, 1).End(xlUp).Row
Set rng = .Range(.Cells(2, 1), .Cells(lstRw, 1))
End With
For Each item In rng
If Not emplDict.exists(item.Value) Then
emplDict.Add item.Text, item.Offset(0, 1).Text
End If
Next
xlWB.Close False
Set xlWS = Nothing
Set xlWB = Nothing
Application.Run "code.xlHelper", True
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Set emplDict = Nothing
End Sub
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…