|
楼主 |
发表于 2024-9-6 08:19
|
显示全部楼层
Option Explicit
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
ActiveCell = ListBoxl.Value
ListBoxl.Clear
ListBoxl.Visible = False
TextBoxl.Value = ""
TextBoxl.Visible = False
End Sub
Private Sub TextBoxl_Change()
Dim Search_Text As String, i As Integer, Data As Variant, k As Integer
If TextBoxl.Value <> "" Then
k = 0
Data = Range("C1").CurrentRegion
For i = 1 To Len(TextBoxl.Value)
Search_Text = Search_Text & Mid(TextBoxl.Value, i, 1) & "*"
Next i
Search Text = "*" & Search_Text
With ListBoxl
.Clear
Visible = True
.Top = TextBoxl.Top
.Left = TextBoxl.Left + TextBoxl.Width
.Width = 100
For i = 2 To UBound(Data)
If Data(i, 1) Like Search_Text Then
.AddItem Data(i, 2)
k = k + 1
End If
Next
.Height = TextBoxl.Height * k
End With
Else
ListBoxl.Visible = False
ListBoxl.Clear
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count <> 1 Then Exit Sub
ListBoxl.Visible = False
If Intersect(Target, Range("Al:A15")) Is Nothing Then
With TextBoxl
.Visible = False
.Value = ""
End With
Else
With TextBoxl
.Value = ""
.Visible = True
.Activate
.Left = Target.Left
.Top = Target.Top
.Height = Target.Height + 3
.Width = Target.Width + 2
End With
End If
End Sub
|
|