首页 > 解决方案 > VBA中的Excel复选框下拉填充选项?

问题描述

我创建了我的列表并将其插入到列表框中,一切看起来都很好,列表框包含我需要的所有字段。我遇到的问题是我的代码......我已经看了好几个小时,但无法弄清楚我的 VBA 代码有什么问题:

这是我的excel表格的截图。基本上单元格 G1:G7 是我需要用户能够选择带有复选框的下拉列表并用逗号分隔的每个数据填充的地方。比如12345、12546、12345等...

Excel 截图

这是我的代码:

Sub Rectangle3_Click()
'Updated by Extendoffice 20191114
Dim xSelShp As Shape, xSelLst As Variant, I As Integer
Set xSelShp = ActiveSheet.Shapes(Application.Caller)
Set xLstBox = ActiveSheet.Drop_Down2
If xLstBox.Visible = False Then
    xLstBox.Visible = True
    xSelShp.TextFrame2.TextRange.Characters.Text = "Please select below:"
Else
    xLstBox.Visible = False
    xSelShp.TextFrame2.TextRange.Characters.Text = "Please select below:"
    For I = xLstBox.ListCount - 1 To 0 Step -1
        If xLstBox.Selected(I) = True Then
        xSelLst = xLstBox.List(I) & ";" & xSelLst
        End If
    Next I
    If xSelLst <> "" Then
        Range("ListBoxOutput") = Mid(xSelLst, 1, Len(xSelLst) - 1)
    Else
        Range("ListBoxOutput") = ""
    End If
End If
End Sub

标签: excelvbabox

解决方案


推荐阅读