【发布时间】:2015-10-21 10:49:07
【问题描述】:
我有一个标题为“下载”的 K 列。我希望能够单击 K 列中的一个单元格,然后出现一个带有复选框的列表框,我从 7 个列表(存储在另一张表中)中选择该用户已下载的文件的名称。然后将它们添加到单元格中,用逗号分隔。
我遇到的问题是 K 列中的每个单元格都需要不同,例如,如果我的下载列表是“项目 A、项目 B、项目 C”等,然后在 K3 中检查项目A,那么它应该只显示项目 A。但是,如果我单击 K29 并选择项目 A、B 和 C,那么它应该在该单元格中显示“项目 A、项目 B、项目 C”。
这是我正在测试的一个示例,它不起作用,因为它用我检查的内容填充了 K 列中的每个单元格。此外,下拉菜单始终可见,我只希望它在单击单元格时可见:
Private Sub ListBox1_Change()
Dim lngCurrentItem As Long
Dim strCurrentItem As String
Dim strAllSelectedItems As String
Dim rngOutput As Range
Set rngOutput = [K1:K999]
strAllSelectedItems = ""
For i = 0 To ListBox1.ListCount - 1
strCurrentItem = ListBox1.List(i)
If ListBox1.Selected(i) Then
If strAllSelectedItems = "" Then
strAllSelectedItems = strCurrentItem
Else
strAllSelectedItems = strAllSelectedItems & " - " & strCurrentItem
End If
End If
Next i
If strAllSelectedItems = "" Then
rngOutput = "No Items Selected"
ElseIf InStr(1, strAllSelectedItems, " - ", vbTextCompare) > 0 Then
rngOutput = strAllSelectedItems & " Are Selected"
Else
rngOutput = strAllSelectedItems & " Is Selected"
End If
End Sub
【问题讨论】:
-
请问您可以发布您当前使用的代码吗?
-
添加到原帖