|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
ActiveCell = .List(i, 0)
.Visible = False
TextBox1.Visible = False
Exit For
End If
Next i
End With
End Sub
Private Sub TextBox1_Change()
zd = TextBox1.Text
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("下拉数据源")
r = .Cells(Rows.Count, 2).End(xlUp).Row
If r < 2 Then MsgBox "下拉数据源为空!": End
ar = .Range("b1:b" & r)
End With
For i = 2 To UBound(ar)
If InStr(ar(i, 1), zd) > 0 Then
d(ar(i, 1)) = ""
End If
Next i
With ListBox1
.Visible = True
.List = d.keys
.Top = ActiveCell.Top
.Left = ActiveCell.Left + 60
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal T As Range)
If T.Row > 4 And T.Column = 4 Then
If T.Count > 1 Then End
With TextBox1
.Visible = True
.Top = T.Top
.Left = T.Left
.Activate
End With
With Sheets("下拉数据源")
r = .Cells(Rows.Count, 2).End(xlUp).Row
If r < 2 Then MsgBox "下拉数据源为空!": End
ar = .Range("b2:b" & r)
End With
With ListBox1
.Visible = True
.List = ar
.Top = ActiveCell.Top
.Left = ActiveCell.Left + 60
End With
Else
TextBox1.Visible = False
ListBox1.Visible = False
TextBox1 = ""
End If
End Sub
|
|