如何在VBA中显示在多选列表框中选择的值

时间:2016-04-29 08:45:06

标签: excel-vba vba excel

您好我一直试图解决这个问题。其他一切都只是错误。 这是最接近的,但它仅显示列表框中的最后一个选定项目。

Dim i As Integer
For i = 0 To SVSListBox1.ListCount - 1 
If SVSListBox1.Selected(i) Then SelectedItemText = SVSListBox1(i) 
End if
Next i 

SVSListBox.Value = SelectedItemText 工作表(“sheet2”)。单元格(startingRow,12).Value = SVSListBox1.value

用iPhone发布。 (抱歉导致我的电脑被锁定,因此我必须在我的iPhone中手动输入它)

1 个答案:

答案 0 :(得分:0)

我不确定您是否在询问此问题,但如果您需要知道如何将所选项目从ListBox写入Worksheet,那么下面的代码可能是一个开始为你指出:

Dim index As Integer
Dim cell As Range

Set cell = Sheet1.Range("A1")
For index = 0 To UserForm1.ListBox1.ListCount - 1
    If UserForm1.ListBox1.Selected(index) Then
        cell.Value = UserForm1.ListBox1.List(index)
        Set cell = cell.Offset(1)
    End If
Next

已针对逗号分隔的项目进行了更新

Dim index As Integer
Dim items As String

For index = 0 To UserForm1.ListBox1.ListCount - 1
    If UserForm1.ListBox1.Selected(index) Then
        If items <> vbNullString Then items = items & ", "
        items = items & UserForm1.ListBox1.List(index)
    End If
Next

Sheet1.Range("A1").Value = items
相关问题