excel - VBA中的Excel复选框下拉填充选项?
问题描述
我创建了我的列表并将其插入到列表框中,一切看起来都很好,列表框包含我需要的所有字段。我遇到的问题是我的代码......我已经看了好几个小时,但无法弄清楚我的 VBA 代码有什么问题:
这是我的excel表格的截图。基本上单元格 G1:G7 是我需要用户能够选择带有复选框的下拉列表并用逗号分隔的每个数据填充的地方。比如12345、12546、12345等...
这是我的代码:
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
解决方案
推荐阅读
- python - 使用 BRISQUE 特征检测放大图像
- mysql - 使用两个表的列之间的外部映射连接 mysql 中的两个表
- java - 重构方法引用以支持参数
- php - SQLSTATE [HY000]:一般错误:1364 字段“contactId”没有默认值
- php - Symfony - 参数语法和重定向
- python - 在 Pytest 中收集测试结果数据
- postgresql - 如何在线使用geoserver + postgresql?
- linux - Linux 服务应用程序创建文件的权限
- javascript - 如何将数组划分为具有灵活输出长度的块?
- c++ - 如何安全使用 QQmlEngine::CppOwnership?