|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Dim d
- Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
- If KeyCode = 13 Then
- If ListBox1.ListIndex = -1 Then Exit Sub
- Dim i&, s$
- With ListBox1
- For i = 0 To .ListCount - 1
- If .Selected(i) Then s = s & "," & .List(i)
- Next
- .TopLeftCell.Offset(, -1).Value = Mid(s, 2)
- .Visible = False
- End With
- End If
- End Sub
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Count > 1 Then Exit Sub
- If Target.Row > 2 And (Target.Column = 2 Or Target.Column = 3) Then
- Dim arr, c&, i&, Brr, bt, r1, aa, bb$, j&
- Set d = CreateObject("Scripting.Dictionary")
- If Target <> "" Then
- If InStr(Target.Value, ",") Then
- aa = Split(Target.Value, ",")
- Else
- bb = Target.Value
- End If
- End If
- Brr = [a1].CurrentRegion
- For i = 1 To UBound(Brr, 2)
- d(Brr(2, i)) = i
- Next
- bt = Brr(2, Target.Column)
- Set r1 = Sheets("值").Rows(1).Find(bt, , , 1)
- c = r1.Column
- arr = Sheets("值").Cells(2, c).Resize(Sheets("值").Cells(Rows.Count, c).End(xlUp).Row - 1)
- With ListBox1
- .MultiSelect = 1
- .ListStyle = 1
- .List = arr
- .Top = Target.Top
- .Left = Target.Left + Target.Width
- .Height = Target.Height * 9
- .Width = 90
- .Visible = True
- For i = 0 To .ListCount - 1
- If bb <> "" Then
- If bb = .List(i) Then .Selected(i) = 1
- Else
- For j = 0 To UBound(aa)
- If aa(j) = .List(i) Then .Selected(i) = 1
- Next
- End If
- Next
- End With
- Else
- ListBox1.Clear
- ListBox1.Visible = False
- End If
- End Sub
复制代码
选择后按回车实现。 |
|