多选列表框以填充到Excel单元格

时间:2018-06-13 19:05:26

标签: excel vba combobox listbox populate

我在工作簿的Sheet1中有一个用户表单来输入数据。它效果很好 文本框,但不适用于多选列表框。我希望将选项填充到相应的excel单元格中,就像文本框一样。由于某种原因,文本框中的文本自动填充到下一个可用行中,列表框中的选项不会。附上是我的代码。

Private Sub Submit_Click()
    Dim lRow As Long
    Dim arrItems()
    Dim cnt As Long
    Dim I As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")
    lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    With ws
        .Cells(lRow, 1).Value = UserForm2.txtCompany.Value
        .Cells(lRow, 2).Value = UserForm2.txtPOC.Value
        .Cells(lRow, 3).Value = UserForm2.txtPhone.Value
        .Cells(lRow, 4).Value = UserForm2.txtEmail.Value
        .Cells(lRow, 5).Value = UserForm2.Contract.Value
        .Cells(lRow, 6).Value = UserForm2.Capability.Value
        .Cells(lRow, 7).Value = UserForm2.Agency.Value
        .Cells(lRow, 8).Value = UserForm2.txtDepartment.Value
        .Cells(lRow, 9).Value = UserForm2.Socioeconomic.Value
        .Cells(lRow, 10).Value = UserForm2.txtNotes.Value
    End With
End Sub

0 个答案:

没有答案