|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本人VBA菜鸟,在网上寻到一个下拉菜单多选的VBA代码,只能做到一列单元格出现下拉选项。如果要另一列单元格也实现下拉选项好像就不行,是不是
Private Sub Worksheet_SelectionChange(ByVal Target As Range在一个worksheet只能运用一次?能不能合并,怎么合并谢谢!!
附件已经为2个下拉选项写好了代码,但不知道怎么合并,需要一个worksheet同时实现下拉多选。。谢谢大家!!!
第一个Blue,第二个Green
- Private Sub ListBoxRS_Change()
- Dim LR As Long
- Dim STR As String
- With ListBoxRS
- For LR = 0 To .ListCount - 1
- If .Selected(LR) = True Then
- STR = STR & "," & .List(LR, 0)
- End If
- Next
- End With
- ActiveCell.Value = Mid(STR, 2)
- End Sub
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Count > 1 Then ListBoxRS.Visible = False: Exit Sub
- If Target.Column = 1 Then ListBoxRS.Visible = False: Exit Sub
- If Target.Column <> 7 Or Target.Row < 3 Or Target.Offset(0, -1) = "" _
- Then ListBoxRS.Visible = False: Exit Sub
- Dim RG
- Dim LR As Long
- LR = Sheet2.Range("A9999").End(xlUp).Row
- RG = Sheet2.Range("A1:A" & LR)
- With ListBoxRS
- .Top = Target.Top
- .Left = Target.Offset(0, 1).Left
- .Width = 310
- .Height = 60
- .Visible = True
- .ColumnCount = 1
- .ColumnWidths = "50;80"
- .List = RG
- End With
- End Sub
复制代码- Private Sub ListBoxFT_Change()
- Dim LR As Long
- Dim STR As String
- With ListBoxFT
- For LR = 0 To .ListCount - 1
- If .Selected(LR) = True Then
- STR = STR & "," & .List(LR, 0)
- End If
- Next
- End With
- ActiveCell.Value = Mid(STR, 2)
- End Sub
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Count > 1 Then ListBoxFT.Visible = False: Exit Sub
- If Target.Column = 1 Then ListBoxFT.Visible = False: Exit Sub
- If Target.Column <> 20 Or Target.Row < 3 Or Target.Offset(0, -1) = "" _
- Then ListBoxFT.Visible = False: Exit Sub
- Dim RG
- Dim LR As Long
- LR = Sheet2.Range("B9999").End(xlUp).Row
- RG = Sheet2.Range("B1:B" & LR)
- With ListBoxFT
- .Top = Target.Top
- .Left = Target.Offset(0, 1).Left
- .Width = 310
- .Height = 60
- .Visible = True
- .ColumnCount = 1
- .ColumnWidths = "50;80"
- .List = RG
- End With
- End Sub
复制代码
|
|