Private pri_Col As Long, pri_ArrData
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
With Sheets("ID Item DE + EE")
pri_ArrData = .Range(Range("A2"), .Range("B" & Rows.Count).End(xlUp))
End With
OptionButton2.Value = True
ListBox1.List = pri_ArrData
End Sub
Private Sub UserForm_Terminate()
Application.ScreenUpdating = True
End Sub
Private Sub TextBox1_Change()
If TextBox1 = "" Then
ListBox1.List = pri_ArrData
Else
Dim GetRows()
Dim ArrFilter
Dim FilterText As String
Dim r As Long, n As Long
FilterText = UCase(TextBox1) & "*"
''Hoac:
''FilterText = "*" & TextBox1 & "*"
For r = 1 To UBound(pri_ArrData)
If UCase(pri_ArrData(r, pri_Col)) Like FilterText Then
n = n + 1
ReDim Preserve GetRows(1 To n)
GetRows(n) = r
End If
Next
If n Then
ReDim ArrFilter(1 To n, 1 To 2)
For r = 1 To n
ArrFilter(r, 1) = pri_ArrData(GetRows(r), 1)
ArrFilter(r, 2) = pri_ArrData(GetRows(r), 2)
Next
ListBox1.List = ArrFilter
Else
ListBox1.List = Array()
End If
End If
End Sub
Private Sub OptionButton1_Change()
If OptionButton1 Then
pri_Col = 1
TextBox1 = ""
TextBox1.SetFocus
End If
End Sub
Private Sub OptionButton2_Change()
If OptionButton2 Then
pri_Col = 2
TextBox1 = ""
TextBox1.SetFocus
End If
End Sub