|
小白一个,借用论坛前辈的程序,制作了一个模糊检索,基本满足需求。但是有个问题:在文本框录入错误,删除全部关键词时,程序将所有数据源检索出来显示在列表框,由于数据源较多,造成检索过程很长,excel卡死。请教各位大神,如何完善代码,以实现:删除全部关键词时,程序不执行检索?
程序代码如下:
- Private Sub ListBox1_Click()
- ActiveCell = ListBox1.Value
- ActiveCell.Offset(0, 1).Select
- End Sub
- Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
- Dim Arr1, myStr$, i&
- With Me.TextBox1
- For i = 1 To Len(.Value)
- If Asc(Mid$(.Value, i, 1)) > 255 Or Asc(Mid$(.Value, i, 1)) < 0 Then
- Language = True
- myStr = myStr & Mid$(.Value, i, 1)
- Else
- myStr = myStr & UCase(Mid$(.Value, i, 1))
- End If
- Next
- End With
- With Sheet5
- Me.ListBox1.Clear
- Arr1 = .Range("a1:a" & .Range("a65535").End(xlUp).Row)
- For i = 1 To UBound(Arr1)
- If InStr(Arr1(i, 1), myStr) Then
- Me.ListBox1.AddItem Arr1(i, 1)
- End If
- Next i
- End With
- End Sub
- <hr class="l">Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Column <> 3 Or Target.Count > 2 Then
- ListBox1.Visible = False
- TextBox1.Visible = False
- Exit Sub
- End If
- With TextBox1
- .Activate
- .Visible = True
- .Value = ""
- .Top = Target.Top
- .Left = Target.Left
- .Width = 500
- .Height = Target.Height + 5
- End With
- With ListBox1
- .Visible = True
- .Top = Target.Offset(0, 1).Top
- .Left = Target.Offset(0, 1).Left
- .Width = 500
- .Height = Target.Height * 10
- .Clear
- End With
- End Sub
复制代码
|
|