|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 aman1516 于 2022-4-30 15:57 编辑
试试:
- <font style="background-color: rgb(255, 255, 255);">Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- On Error Resume Next
- Dim aa, bb, cc
- If Target.Count > 1 Then Exit Sub
- Application.EnableEvents = False
- bb = Target.Value
- If bb <> "" Then
- aa = Split(bb, ",")
- End If
- cc = Target.Column
- Select Case cc
- Case 9, 17
- With ListBox1
- .Clear
- .MultiSelect = 1
- .ListStyle = 0
- .Top = ActiveCell(1, 2).Top + 17
- .Left = ActiveCell(1, 2).Left
- .List = Application.Transpose(Sheets("数据").Range("A1:A" & Sheets("数据").Range("A65536").End(xlUp).Row))
- .Height = Target.Height * 12
- .Width = Target.Width + 20
- .Visible = True
- If bb <> "" Then
- For i = 0 To .ListCount - 1
- For j = 0 To UBound(aa)
- If aa(j) = .List(i) Then .Selected(i) = 1
- Next
- Next
- End If
- End With
- Application.EnableEvents = True
- Case 8, 16
- With ListBox1
- .Clear
- .MultiSelect = 1
- .ListStyle = 0
- .Top = ActiveCell(1, 2).Top + 17
- .Left = ActiveCell(1, 2).Left
- .List = Application.Transpose(Sheets("数据").Range("B1:B" & Sheets("数据").Range("B65536").End(xlUp).Row))
- .Height = Target.Height * 12
- .Width = Target.Width + 20
- .Visible = True
- If bb <> "" Then
- For i = 0 To .ListCount - 1
- For j = 0 To UBound(aa)
- If aa(j) = .List(i) Then .Selected(i) = 1
- Next
- Next
- End If
- End With
- Case Else
- ListBox1.Clear
- ListBox1.Visible = False
- End Select
- Application.EnableEvents = True
- End Sub</font>
复制代码 |
|