|
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) Then
ActiveCell.Value = Me.ListBox1.List(i, 0)
Me.ListBox1.Visible = False
Me.ListBox1.Clear
Me.TextBox1 = ""
Me.TextBox1.Visible = False
Exit For
End If
Next
End Sub
Private Sub TextBox1_Change()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Me.ListBox1.Clear
arr = Sheets("库存").Range("a2:a" & Sheets("库存").Range("a65536").End(xlUp).Row)
If Len(Me.TextBox1.Value) <> 0 Then
For ii = LBound(arr) To UBound(arr)
If InStr(arr(ii, 1), Me.TextBox1.Value) > 0 Then
If Not d.exists(arr(ii, 1)) Then
Me.ListBox1.AddItem arr(ii, 1)
d(arr(ii, 1)) = ""
End If
End If
Next
If Me.ListBox1.ListCount > 0 Then
Me.ListBox1.Visible = True
Me.ListBox1.Left = ActiveCell.Left
Me.ListBox1.Width = ActiveCell.Width
Else
Me.ListBox1.Visible = False
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 2 And Target.Row > 1 Then
Me.TextBox1.Top = Target.Top
Me.TextBox1.Left = Target.Left
Me.TextBox1.Width = Target.Width
Me.TextBox1.Height = Target.Height
Me.TextBox1.Visible = True
Me.ListBox1.Left = Target.Left
Me.ListBox1.Width = Target.Width
Me.TextBox1.Activate '
Else
Me.ListBox1.Visible = False
Me.ListBox1.Clear
Me.TextBox1 = ""
Me.TextBox1.Visible = False
End If
End Sub
|
|