|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Column > 8 Or Target.Row < 4 Or Target.Row > 5 Then GoTo 100
- Dim Arr, d, col$, j&
- Target = ""
- col = "1478"
- j = InStr(col, Target.Column)
- Set d = CreateObject("Scripting.Dictionary")
- Arr = [l1].CurrentRegion
- For i = 2 To UBound(Arr)
- If Arr(i, j) = "" Then Exit For
- d(Arr(i, j)) = ""
- Next
- With Me.ListBox1
- .Visible = True
- .Top = [c6].Top
- .Left = Cells(5, Target.Column).Left
- .Clear
- .List = d.keys
- End With
- Exit Sub
- 100:
- With Me.ListBox1
- .Visible = False
- End With
- End Sub
- Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
- Dim i&, aa$, bb$
- If KeyCode = 13 Then '回车
- If ListBox1.ListCount > 0 Then
- For i = 0 To ListBox1.ListCount - 1
- If ListBox1.Selected(i) Then
- aa = aa & ListBox1.List(i) & vbCrLf
- End If
- Next
- ActiveCell = aa
- Me.ListBox1.Clear
- Me.ListBox1.Visible = False
- KeyCode = 0
- ActiveCell.Offset(1, 0).Select
- End If
- End If
- End Sub
复制代码 |
|