这里有3个地方要加,看来这个.LIst的属性真的有些问题呢 Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) '事件模糊匹配 Selection = TextBox1.Text Dim arr, arr2(), i As Long, n As Long, zh As String arr = Sheet1.[a2].Resize(Sheet1.[a65536].End(xlUp).Row - 1, 1) zh = TextBox1.Text & "*" For i = 1 To UBound(arr) If arr(i, 1) Like zh Then n = n + 1 ReDim Preserve arr2(1 To n) arr2(n) = arr(i, 1) End If Next If n > 0 Then ListBox1.List() = WorksheetFunction.Transpose(arr2) ListBox1.Visible = True Else ListBox1.List() = Array("") End If ListBox1.Width = 80 End Sub Private Sub ListBox1_Click() TextBox1.Visible = False With Sheet2.ListBox1 Selection = .Text .List = Array("") .Width = 80 .Visible = False End With End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Column = 1 And Target.Count = 1 Then Dim ta As Range, taf As Range Set ta = Target: Set taf = Target.Offset(0, 1) With Sheet2.TextBox1 .Left = ta.Left .Top = ta.Top .Height = ta.Height .Width = ta.Width .Activate .Text = ta .Visible = True End With If Len(ta.Text) = 0 Then With Sheet2.ListBox1 .Top = taf.Top .Visible = True End With Else With Sheet2.ListBox1 .Visible = False .Top = taf.Top End With End If If Len(ta.Text) = 0 Then Application.SendKeys "{BS}" Else If Sheet2.TextBox1.Visible = True Then With Sheet2.TextBox1 .Text = "" .Visible = False End With End If If Sheet2.ListBox1.Visible = True Then With Sheet2.ListBox1 .List = Array("") .Width = 80 .Visible = False End With End If End If End Sub
|