我想从多选列表框中获取所选项目,并将这些项目放在下面的列中。我已经知道如何获取所选项目,但不知道如何将这些项目放入工作表中。
下载代码:
Private Sub CommandButton2_Click()
Dim Msg As String
Dim i As Integer
Dim reihe As Integer
Dim spalte As Variant
reihe = 30
spalte = "A"
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = Msg & ListBox1.List(i) & vbNewLine
End If
Next i
MsgBox Msg
End Sub
答案 0 :(得分:0)
假设我们要将值放在 B 列中,从第13行开始。在 MsgBox 之后,请包含:
ary = Split(Msg, vbCrLf)
J = 13
For Each a In ary
Cells(J, "B").Value = a
J = J + 1
Next a
修改#1:强>
要从同一点开始,但要填写,请使用:
ary = Split(Msg, vbCrLf)
J = 13
K = 2
For Each a In ary
Cells(J, K).Value = a
K = K + 1
Next a