2016-04-29 41 views
0

嗨,我一直在试图解决这个问题。其他一切都只是错误。 这是最接近的,但它只显示列表框中最后选择的项目。如何在VBA中显示在多选列表框中选择的值

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 工作表( “Sheet 2中”)。将细胞(startingRow,12)。价值= SVSListBox1.value

发布与IPhone。 (对不起,我的电脑被锁定,所以我不得不在我的iPhone手动输入)

回答

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 
+0

是的!这是我想要的。但是有没有办法让我将所选的值显示到一个单元格中?通常用于分开它们。 @Ambie – Gwen

+0

查看我的更新回答。 – Ambie

+0

我明白了,这是如何完成的!这就是我想要的!谢谢!! @Ambie – Gwen

相关问题